From 640dfb90ae932817425c316baa473563257c151d Mon Sep 17 00:00:00 2001 From: cdcolor7 <276214101@qq.com> Date: Sat, 17 Apr 2021 22:19:34 +0800 Subject: [PATCH] init --- .babel.js | 5 + .gitignore | 4 + dist/vue.js | 372 +++++++++++++++ dist/vue.js.map | 1 + examples/index.html | 37 ++ package-lock.json | 1096 +++++++++++++++++++++++++++++++++++++++++++ package.json | 19 + rollup.config.js | 22 + src/array.js | 40 ++ src/compile.js | 118 +++++ src/dep.js | 27 ++ src/entry-dev.js | 146 ++++++ src/observer.js | 95 ++++ src/patch.js | 3 + src/util.js | 61 +++ src/watcher.js | 33 ++ 16 files changed, 2079 insertions(+) create mode 100644 .babel.js create mode 100644 .gitignore create mode 100644 dist/vue.js create mode 100644 dist/vue.js.map create mode 100644 examples/index.html create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 rollup.config.js create mode 100644 src/array.js create mode 100644 src/compile.js create mode 100644 src/dep.js create mode 100644 src/entry-dev.js create mode 100644 src/observer.js create mode 100644 src/patch.js create mode 100644 src/util.js create mode 100644 src/watcher.js diff --git a/.babel.js b/.babel.js new file mode 100644 index 0000000..81c35e2 --- /dev/null +++ b/.babel.js @@ -0,0 +1,5 @@ +{ + presets: [ + ["es2015", { "modules": false }] + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a62c223 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +node_modules +*.log +.vscode diff --git a/dist/vue.js b/dist/vue.js new file mode 100644 index 0000000..d3acac5 --- /dev/null +++ b/dist/vue.js @@ -0,0 +1,372 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.Pvue = factory()); +}(this, (function () { 'use strict'; + +/** + * 消息管理器 + */ + +class Dep { + constructor() { + this.deps = new Set(); + } + + // 添加订阅者 + addSub(watcher) { + this.deps.add(watcher); + } + + // 操作watcher addDep 方法 + depend() { + if (Dep.target) { + Dep.target.addDep(this); + } + } + + // 通知更新 + notify() { + this.deps.forEach(watcher => watcher.update()); + } + +} + +// 返回指定 key 对应的 data值 + + +// 设置指定 key 对应的 data值 + + +// 定义一个Property +function def(obj, key, val, enumerable) { + Object.defineProperty(obj, key, { + value: val, + enumerable: !!enumerable, + writable: true, + configurable: true + }); +} + +// 数组响应式处理 +function dependArray(value) { + for (let e, i = 0, l = value.length; i < l; i++) { + e = value[i]; + e && e.__ob__ && e.__ob__.dep.depend(); + if (Array.isArray(e)) { + dependArray(e); + } + } +} + +// 检测一个对象的属性是否存在 +const hasOwnProperty = Object.prototype.hasOwnProperty; +function hasOwn(obj, key) { + return hasOwnProperty.call(obj, key); +} + +/** + * 数组函数劫持 + */ + +const arrayProto = Array.prototype; + +const arrayMethods = Object.create(arrayProto); + +const methodsToPatch = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"]; + +methodsToPatch.forEach(function (method) { + // 保存原始方法 + const original = arrayProto[method]; + // 覆盖之 + def(arrayMethods, method, function (...args) { + // 1.执行默认方法 + const result = original.apply(this, args); + // 2.变更通知 + const ob = this.__ob__; + // 可能会有新元素加入 + let inserted; + switch (method) { + case 'push': + case 'unshift': + inserted = args; + break; + case 'splice': + inserted = args.slice(2); + break; + } + // 对新加入的元素做响应式 + if (inserted) ob.observeArray(inserted); + // notify change + // ob内部有一个dep,让它去通知更新 + ob.dep.notify(); + return result; + }); +}); + +/** + * 响应式数据 + */ + +class Observer { + constructor(value) { + this.value = value; + this.dep = new Dep(); + def(value, '__ob__', this); + if (Array.isArray(value)) { + if ('__proto__' in {}) { + value.__proto__ = arrayMethods; + } + this.observeArray(value); + } else { + this.walk(value); + } + } + + // 数组响应式处理 + observeArray(arr) { + for (let i = 0, l = arr.length; i < l; i++) { + observe(arr[i]); + } + } + + // 对象响应式处理 + walk(obj) { + Object.keys(obj).forEach(key => { + defineReactive(obj, key, obj[key]); + }); + } +} + +// 数据劫持 +function defineReactive(obj, key, val) { + let childOb = observe(val); + // 每一可以对应一个 dep; + const dep = new Dep(); + Object.defineProperty(obj, key, { + get() { + // 依赖收集 + dep.depend(); + if (childOb) { + // 子ob也要做依赖收集 + childOb.dep.depend(); + if (Array.isArray(val)) { + dependArray(val); + } + } + return val; + }, + set(newVal) { + if (val !== newVal) { + observe(newVal); + val = newVal; + // 通知更新 + dep.notify(); + } + } + }); +} + +// observe +function observe(obj) { + if (typeof obj !== 'object' || obj === null) { + return; + } + let ob; + if (hasOwn(obj, '__ob__') && obj.__ob__ instanceof Observer) { + ob = obj.__ob__; + } else { + ob = new Observer(obj); + } + return ob; +} + +// porxy +function proxy(vm) { + Object.keys(vm.$data).forEach(key => { + Object.defineProperty(vm, key, { + get() { + return vm.$data[key]; + }, + set(newVal) { + vm.$data[key] = newVal; + } + }); + }); +} + +/** + * 依赖收集 + */ + +class Watcher { + constructor(vm, updaterFn) { + this.vm = vm; + this.getter = updaterFn; + + // 依赖收集 + this.get(); + } + + get() { + Dep.target = this; + this.getter.call(this.vm); + Dep.target = null; + } + + // 相互添加引用 + addDep(dep) { + dep.addSub(this); + } + + update() { + this.get(); + // this.updaterFn.call(this.vm, getDataVal.call(this.vm, this.key)) + } + +} + +/** + * 编译器 + */ + +/** + * 入口文件 +*/ + +class Pvue { + constructor(options) { + this.$options = options; + this.$data = options.data; + observe(this.$data); + + // 代理data + proxy(this); + + // 代理methods + for (const key in options.methods) { + this[key] = typeof options.methods[key] === 'function' ? options.methods[key].bind(this) : noop; + } + + // 模板编译 + // new Compile(options.el, this) + if (options.el) { + this.$mount(options.el); + } + } + + // 挂载 + $mount(el) { + // 获取宿主原始 + this.$el = document.querySelector(el); + // 组件更新函数 + const updateComponent = () => { + // const { render } = this.$options; + // const el = render.call(this); + // const parent = this.$el.parentElement; + // parent.insertBefore(el, this.$el.nextSibling); + // parent.removeChild(this.$el); + // this.$el = el; + const { render } = this.$options; + const vnode = render.call(this, this.$createElement); + this._update(vnode); + }; + // 创建wather + new Watcher(this, updateComponent); + } + + // 获取vnode + $createElement(tag, props, children) { + return { tag, props, children }; + } + // 更新 + _update(vnode) { + const preVnode = this._vnode; + if (preVnode) { + // 更新 + this.__patch__(preVnode, vnode); + } else { + // 初始化 + this.__patch__(this.$el, vnode); + } + } + // patch方法 + __patch__(oldVode, vnode) { + // 判断old是否为dom + if (oldVode.nodeType) { + // 初始化 + const parent = oldVode.parentElement; + const refElm = oldVode.nextSibling; + // 递归vnode创建dom树 + const el = this.createElm(vnode); + parent.insertBefore(el, refElm); + parent.removeChild(oldVode); + } else { + // 更新 + const el = vnode.el = oldVode.el; + // 判断是否是相同节点samenode + if (oldVode.tag === vnode.tag) { + // diff + // props + // children + const oldCh = oldVode.children; + const newCh = vnode.children; + if (typeof newCh === 'string') { + if (typeof oldCh === 'string') { + if (newCh !== oldCh) { + el.textContent = newCh; + } + } else { + // 清空并替换为文本 + el.textContent = newCh; + } + } else { + // 数组 + if (typeof oldCh === 'string') { + el.innerHTML = ''; + newCh.forEach(child => { + el.appendChild(this.createElm(child)); + }); + } else { + // 双方都有孩子 diff + this.updateChildren(el, oldCh, newCh); + } + } + } + } + // 保存vnode + this._vnode = vnode; + } + // 创建真实节点 + createElm(vnode) { + const el = document.createElement(vnode.tag); + // props + for (const key in vnode.props) { + el.setAttribute(key, vnode.props[key]); + } + + // 处理子节点 + if (vnode.children) { + if (typeof vnode.children !== 'object') { + el.textContent = vnode.children; + } else { + // 数组类子元素 + vnode.children.forEach(vnode => { + el.appendChild(this.createElm(vnode)); + }); + } + } + vnode.el = el; + return el; + } + // 更新子元素 + updateChildren(el, oldCh, newCh) {} +} + +// 空函数 +function noop() {} + +return Pvue; + +}))); +//# sourceMappingURL=vue.js.map diff --git a/dist/vue.js.map b/dist/vue.js.map new file mode 100644 index 0000000..7d6fd2a --- /dev/null +++ b/dist/vue.js.map @@ -0,0 +1 @@ +{"version":3,"file":"vue.js","sources":["../src/dep.js","../src/util.js","../src/array.js","../src/observer.js","../src/watcher.js","../src/compile.js","../src/entry-dev.js"],"sourcesContent":["/**\r\n * 消息管理器\r\n */\r\n\r\nexport class Dep {\r\n constructor() {\r\n this.deps = new Set();\r\n }\r\n\r\n // 添加订阅者\r\n addSub(watcher) {\r\n this.deps.add(watcher);\r\n }\r\n\r\n // 操作watcher addDep 方法\r\n depend () {\r\n if (Dep.target) {\r\n Dep.target.addDep(this)\r\n }\r\n }\r\n\r\n // 通知更新\r\n notify() {\r\n this.deps.forEach(watcher => watcher.update());\r\n }\r\n \r\n}","// 返回指定 key 对应的 data值\r\nexport function getDataVal(exp) {\r\n let value\r\n if(/\\[|\\|]|\\./.test(exp)) {\r\n let keyArr = exp.replace(/\\]/g, '').split(/\\[|\\./g);\r\n keyArr.forEach((key, index) => {\r\n value = index === 0? this[key]: value[key];\r\n })\r\n } else {\r\n value = this[exp]\r\n }\r\n return value;\r\n}\r\n\r\n// 设置指定 key 对应的 data值\r\nexport function setDataVal(exp, value) {\r\n let val\r\n if(/\\[|\\|]|\\./.test(exp)) {\r\n let keyArr = exp.replace(/\\]/g, '').split(/\\[|\\./g);\r\n let l = keyArr.length -1 ;\r\n keyArr.forEach((key, index) => {\r\n if(index === 0) {\r\n val = this[key]\r\n } else if (index === l){\r\n val[key] = value\r\n } else {\r\n val = val[key]\r\n }\r\n })\r\n } else {\r\n this[exp] = value\r\n }\r\n}\r\n\r\n\r\n// 定义一个Property\r\nexport function def(obj, key, val, enumerable) {\r\n Object.defineProperty(obj, key, {\r\n value: val,\r\n enumerable: !!enumerable,\r\n writable: true,\r\n configurable: true\r\n })\r\n}\r\n\r\n// 数组响应式处理\r\nexport function dependArray (value) {\r\n for (let e, i = 0, l = value.length; i < l; i++) {\r\n e = value[i]\r\n e && e.__ob__ && e.__ob__.dep.depend()\r\n if (Array.isArray(e)) {\r\n dependArray(e)\r\n }\r\n }\r\n}\r\n\r\n// 检测一个对象的属性是否存在\r\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\r\nexport function hasOwn(obj, key){\r\n return hasOwnProperty.call(obj, key)\r\n}\r\n","/**\r\n * 数组函数劫持\r\n */\r\n\r\nimport {def} from \"./util\"\r\n\r\nconst arrayProto = Array.prototype\r\n\r\nexport const arrayMethods = Object.create(arrayProto)\r\n\r\nconst methodsToPatch = [\"push\", \"pop\", \"shift\", \"unshift\", \"splice\", \"sort\", \"reverse\"]\r\n\r\nmethodsToPatch.forEach(function (method) {\r\n // 保存原始方法\r\n const original = arrayProto[method]\r\n // 覆盖之\r\n def(arrayMethods, method, function (...args) {\r\n // 1.执行默认方法\r\n const result = original.apply(this, args)\r\n // 2.变更通知\r\n const ob = this.__ob__\r\n // 可能会有新元素加入\r\n let inserted\r\n switch (method) {\r\n case 'push':\r\n case 'unshift':\r\n inserted = args\r\n break\r\n case 'splice':\r\n inserted = args.slice(2)\r\n break\r\n }\r\n // 对新加入的元素做响应式\r\n if (inserted) ob.observeArray(inserted)\r\n // notify change\r\n // ob内部有一个dep,让它去通知更新\r\n ob.dep.notify()\r\n return result\r\n })\r\n})\r\n","/**\r\n * 响应式数据\r\n */\r\n\r\nimport { Dep } from './dep'\r\nimport { arrayMethods } from './array'\r\nimport { def, hasOwn, dependArray } from './util'\r\n\r\nexport class Observer {\r\n constructor(value) {\r\n this.value = value;\r\n this.dep = new Dep()\r\n def(value, '__ob__', this)\r\n if(Array.isArray(value)) {\r\n if('__proto__' in {}) {\r\n value.__proto__ = arrayMethods;\r\n }\r\n this.observeArray(value)\r\n } else {\r\n this.walk(value)\r\n }\r\n }\r\n\r\n // 数组响应式处理\r\n observeArray(arr) {\r\n for(let i=0, l = arr.length; i {\r\n defineReactive(obj, key, obj[key]);\r\n })\r\n }\r\n}\r\n\r\n// 数据劫持\r\nexport function defineReactive(obj, key, val){\r\n let childOb = observe(val);\r\n // 每一可以对应一个 dep;\r\n const dep = new Dep();\r\n Object.defineProperty(obj, key, {\r\n get() {\r\n // 依赖收集\r\n dep.depend();\r\n if (childOb) {\r\n // 子ob也要做依赖收集\r\n childOb.dep.depend()\r\n if (Array.isArray(val)) {\r\n dependArray(val)\r\n }\r\n }\r\n return val;\r\n },\r\n set(newVal) {\r\n if(val !== newVal) {\r\n observe(newVal);\r\n val = newVal;\r\n // 通知更新\r\n dep.notify();\r\n }\r\n }\r\n })\r\n}\r\n\r\n// observe\r\nexport function observe(obj) {\r\n if(typeof obj !== 'object' || obj === null) {\r\n return;\r\n }\r\n let ob;\r\n if(hasOwn(obj, '__ob__') && obj.__ob__ instanceof Observer) {\r\n ob = obj.__ob__\r\n } else {\r\n ob = new Observer(obj);\r\n }\r\n return ob;\r\n}\r\n\r\n// porxy\r\nexport function proxy(vm) {\r\n Object.keys(vm.$data).forEach(key => {\r\n Object.defineProperty(vm, key, {\r\n get() {\r\n return vm.$data[key]\r\n },\r\n set(newVal) {\r\n vm.$data[key] = newVal;\r\n }\r\n })\r\n })\r\n}\r\n\r\n","/**\r\n * 依赖收集\r\n */\r\n\r\nimport { Dep } from \"./dep\";\r\nimport { getDataVal } from \"./util\"\r\n\r\nexport class Watcher {\r\n constructor(vm, updaterFn) {\r\n this.vm = vm;\r\n this.getter = updaterFn;\r\n\r\n // 依赖收集\r\n this.get();\r\n }\r\n\r\n get() {\r\n Dep.target = this;\r\n this.getter.call(this.vm);\r\n Dep.target = null;\r\n }\r\n \r\n // 相互添加引用\r\n addDep (dep) {\r\n dep.addSub(this)\r\n }\r\n\r\n update() {\r\n this.get();\r\n // this.updaterFn.call(this.vm, getDataVal.call(this.vm, this.key))\r\n }\r\n \r\n}","/**\r\n * 编译器\r\n */\r\n\r\nimport { Watcher } from './watcher'\r\nimport { getDataVal, setDataVal } from './util'\r\n\r\nexport class Compile {\r\n constructor(el, vm) {\r\n this.$vm = vm;\r\n this.$el = document.querySelector(el);\r\n if(this.$el) {\r\n this.compile(this.$el);\r\n }\r\n }\r\n\r\n // 递归子节点\r\n compile(el) {\r\n const childNodes = el.childNodes;\r\n childNodes.forEach(node => {\r\n if(node.nodeType === 1) { // 元素节点\r\n this.compileElement(node);\r\n // 递归\r\n if(node.hasChildNodes) {\r\n this.compile(node);\r\n }\r\n } else if (this.isInter(node)) { // {{}}\r\n this.compileText(node);\r\n }\r\n })\r\n }\r\n\r\n // 正则 {{counter}}\r\n isInter(node) {\r\n return node.nodeType === 3 && /\\{\\{(.*)\\}\\}/.test(node.textContent);\r\n }\r\n\r\n // 编译属性\r\n compileElement(node) {\r\n let nodeAttrs = node.attributes;\r\n Array.from(nodeAttrs).forEach(attr => {\r\n // v-text=\"xxx\"\r\n const attrname = attr.name; // v-text\r\n const exp = attr.value; // xxx\r\n // 指令解析\r\n if(attrname.indexOf(\"v-\") === 0) {\r\n const dir = attrname.substring(2);\r\n const dirArr = dir.split(':')\r\n if(dirArr.length === 2 && dirArr[0] === 'on') { // 判断 v-on:click =\"onclick\"\r\n this.eventHandler(node, exp, dirArr[1])\r\n } else {\r\n this[dir] && this[dir](node, exp)\r\n }\r\n } else if (attrname.indexOf(\"@\") === 0) { // 判断 @click =\"onclick\"\r\n const dir = attrname.substring(1);\r\n this.eventHandler(node, exp, dir)\r\n }\r\n })\r\n }\r\n\r\n // 事件处理\r\n eventHandler(node, exp, event) {\r\n const fn = this.$vm[exp]\r\n if(event && fn) {\r\n node.addEventListener(event, fn.bind(this.$vm), false);\r\n }\r\n }\r\n\r\n // 处理文本节点\r\n compileText(node) {\r\n this.update(node, RegExp.$1, 'text');\r\n }\r\n\r\n\r\n // 更新中转函数\r\n update(node, exp, dir) {\r\n const fn = this[`${dir}Updater`];\r\n fn && fn(node, getDataVal.call(this.$vm, exp));\r\n // 依赖wather初始化\r\n new Watcher(this.$vm, exp, val => {\r\n fn && fn(node, val)\r\n })\r\n }\r\n\r\n // v-model\r\n modelUpdater(node, value) {\r\n node.value = value\r\n }\r\n\r\n // 文本节点\r\n textUpdater(node, value) {\r\n node.textContent = value;\r\n }\r\n\r\n // html标签解析节点\r\n htmlUpdater(node, value) {\r\n node.innerHTML = value;\r\n }\r\n\r\n // v-model\r\n model(node, exp) {\r\n this.update(node, exp, 'model');\r\n node.addEventListener('input', e => {\r\n setDataVal.call(this.$vm, exp, e.target.value)\r\n })\r\n }\r\n\r\n // v-text\r\n text(node, exp) {\r\n this.update(node, exp, 'text')\r\n }\r\n \r\n // v-html\r\n html(node, exp) {\r\n this.update(node, exp, 'html')\r\n }\r\n\r\n}\r\n","/** \r\n * 入口文件\r\n*/\r\n\r\nimport { observe, proxy } from './observer.js'\r\nimport { Compile } from './compile'\r\nimport { Watcher } from './watcher'\r\n\r\nexport default class Pvue {\r\n constructor(options) {\r\n this.$options = options;\r\n this.$data = options.data;\r\n observe(this.$data)\r\n\r\n // 代理data\r\n proxy(this)\r\n\r\n // 代理methods\r\n for(const key in options.methods) {\r\n this[key] = typeof options.methods[key] === 'function'? options.methods[key].bind(this): noop;\r\n }\r\n\r\n // 模板编译\r\n // new Compile(options.el, this)\r\n if(options.el) {\r\n this.$mount(options.el);\r\n }\r\n }\r\n\r\n // 挂载\r\n $mount(el){\r\n // 获取宿主原始\r\n this.$el = document.querySelector(el);\r\n // 组件更新函数\r\n const updateComponent = () => {\r\n // const { render } = this.$options;\r\n // const el = render.call(this);\r\n // const parent = this.$el.parentElement;\r\n // parent.insertBefore(el, this.$el.nextSibling);\r\n // parent.removeChild(this.$el);\r\n // this.$el = el;\r\n const { render } = this.$options;\r\n const vnode = render.call(this, this.$createElement);\r\n this._update(vnode);\r\n\r\n }\r\n // 创建wather\r\n new Watcher(this, updateComponent);\r\n }\r\n\r\n // 获取vnode\r\n $createElement(tag, props, children) {\r\n return { tag, props, children };\r\n }\r\n // 更新\r\n _update(vnode) {\r\n const preVnode = this._vnode;\r\n if(preVnode) { // 更新\r\n this.__patch__(preVnode, vnode)\r\n } else { // 初始化\r\n this.__patch__(this.$el, vnode)\r\n }\r\n }\r\n // patch方法\r\n __patch__(oldVode, vnode){\r\n // 判断old是否为dom\r\n if(oldVode.nodeType) { // 初始化\r\n const parent = oldVode.parentElement;\r\n const refElm = oldVode.nextSibling;\r\n // 递归vnode创建dom树\r\n const el = this.createElm(vnode);\r\n parent.insertBefore(el, refElm);\r\n parent.removeChild(oldVode);\r\n } else { // 更新\r\n const el = vnode.el = oldVode.el;\r\n // 判断是否是相同节点samenode\r\n if(oldVode.tag === vnode.tag) {\r\n // diff\r\n // props\r\n // children\r\n const oldCh = oldVode.children;\r\n const newCh = vnode.children;\r\n if(typeof newCh === 'string') {\r\n if(typeof oldCh === 'string') {\r\n if(newCh !== oldCh) {\r\n el.textContent = newCh;\r\n }\r\n } else {\r\n // 清空并替换为文本\r\n el.textContent = newCh;\r\n }\r\n } else {\r\n // 数组\r\n if(typeof oldCh === 'string') {\r\n el.innerHTML = '';\r\n newCh.forEach(child => {\r\n el.appendChild(this.createElm(child));\r\n })\r\n } else { // 双方都有孩子 diff \r\n this.updateChildren(el, oldCh, newCh);\r\n }\r\n }\r\n }\r\n\r\n\r\n }\r\n // 保存vnode\r\n this._vnode = vnode;\r\n \r\n }\r\n // 创建真实节点\r\n createElm(vnode) {\r\n const el = document.createElement(vnode.tag);\r\n // props\r\n for (const key in vnode.props) {\r\n el.setAttribute(key, vnode.props[key]);\r\n }\r\n\r\n // 处理子节点\r\n if(vnode.children) {\r\n if(typeof vnode.children !== 'object') {\r\n el.textContent = vnode.children;\r\n } else {\r\n // 数组类子元素\r\n vnode.children.forEach(vnode => {\r\n el.appendChild(this.createElm(vnode));\r\n })\r\n }\r\n }\r\n vnode.el = el;\r\n return el;\r\n }\r\n // 更新子元素\r\n updateChildren(el, oldCh, newCh){}\r\n}\r\n\r\n// 空函数\r\nfunction noop(){}"],"names":["Dep","deps","Set","watcher","add","target","addDep","forEach","update","def","obj","key","val","enumerable","defineProperty","dependArray","value","e","i","l","length","__ob__","dep","depend","Array","isArray","hasOwnProperty","Object","prototype","hasOwn","call","arrayProto","arrayMethods","create","methodsToPatch","method","original","args","result","apply","ob","inserted","slice","observeArray","notify","Observer","__proto__","walk","arr","keys","defineReactive","childOb","observe","newVal","proxy","vm","$data","Watcher","updaterFn","getter","get","addSub","Pvue","options","$options","data","methods","bind","noop","el","$mount","$el","document","querySelector","updateComponent","render","vnode","$createElement","_update","tag","props","children","preVnode","_vnode","__patch__","oldVode","nodeType","parent","parentElement","refElm","nextSibling","createElm","insertBefore","removeChild","oldCh","newCh","textContent","innerHTML","child","appendChild","updateChildren","createElement","setAttribute"],"mappings":"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"} \ No newline at end of file diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 0000000..f4116d9 --- /dev/null +++ b/examples/index.html @@ -0,0 +1,37 @@ + + + + + + 手写VUE + + +
+ +
+ + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c7a6cc6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1096 @@ +{ + "name": "vuedev", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "acorn": { + "version": "5.7.4", + "resolved": "https://registry.npm.taobao.org/acorn/download/acorn-5.7.4.tgz?cache=0&sync_timestamp=1611561275462&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Facorn%2Fdownload%2Facorn-5.7.4.tgz", + "integrity": "sha1-Po2KmUfQWZoXltECJddDL0pKz14=", + "dev": true + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npm.taobao.org/ansi-regex/download/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "dev": true, + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + } + }, + "babel-core": { + "version": "6.26.3", + "resolved": "https://registry.npm.taobao.org/babel-core/download/babel-core-6.26.3.tgz", + "integrity": "sha1-suLwnjQtDwyI4vAuBneUEl51wgc=", + "dev": true, + "requires": { + "babel-code-frame": "^6.26.0", + "babel-generator": "^6.26.0", + "babel-helpers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-register": "^6.26.0", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "convert-source-map": "^1.5.1", + "debug": "^2.6.9", + "json5": "^0.5.1", + "lodash": "^4.17.4", + "minimatch": "^3.0.4", + "path-is-absolute": "^1.0.1", + "private": "^0.1.8", + "slash": "^1.0.0", + "source-map": "^0.5.7" + } + }, + "babel-generator": { + "version": "6.26.1", + "resolved": "https://registry.npm.taobao.org/babel-generator/download/babel-generator-6.26.1.tgz", + "integrity": "sha1-GERAjTuPDTWkBOp6wYDwh6YBvZA=", + "dev": true, + "requires": { + "babel-messages": "^6.23.0", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "detect-indent": "^4.0.0", + "jsesc": "^1.3.0", + "lodash": "^4.17.4", + "source-map": "^0.5.7", + "trim-right": "^1.0.1" + }, + "dependencies": { + "jsesc": { + "version": "1.3.0", + "resolved": "https://registry.npm.taobao.org/jsesc/download/jsesc-1.3.0.tgz?cache=0&sync_timestamp=1603891175833&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsesc%2Fdownload%2Fjsesc-1.3.0.tgz", + "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=", + "dev": true + } + } + }, + "babel-helper-call-delegate": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-call-delegate/download/babel-helper-call-delegate-6.24.1.tgz", + "integrity": "sha1-7Oaqzdx25Bw0YfiL/Fdb0Nqi340=", + "dev": true, + "requires": { + "babel-helper-hoist-variables": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-helper-define-map": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-helper-define-map/download/babel-helper-define-map-6.26.0.tgz", + "integrity": "sha1-pfVtq0GiX5fstJjH66ypgZ+Vvl8=", + "dev": true, + "requires": { + "babel-helper-function-name": "^6.24.1", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "lodash": "^4.17.4" + } + }, + "babel-helper-function-name": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-function-name/download/babel-helper-function-name-6.24.1.tgz", + "integrity": "sha1-00dbjAPtmCQqJbSDUasYOZ01gKk=", + "dev": true, + "requires": { + "babel-helper-get-function-arity": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-helper-get-function-arity": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-get-function-arity/download/babel-helper-get-function-arity-6.24.1.tgz", + "integrity": "sha1-j3eCqpNAfEHTqlCQj4mwMbG2hT0=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-helper-hoist-variables": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-hoist-variables/download/babel-helper-hoist-variables-6.24.1.tgz", + "integrity": "sha1-HssnaJydJVE+rbyZFKc/VAi+enY=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-helper-optimise-call-expression": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-optimise-call-expression/download/babel-helper-optimise-call-expression-6.24.1.tgz", + "integrity": "sha1-96E0J7qfc/j0+pk8VKl4gtEkQlc=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-helper-regex": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-helper-regex/download/babel-helper-regex-6.26.0.tgz", + "integrity": "sha1-MlxZ+QL4LyS3T6zu0DY5VPZJXnI=", + "dev": true, + "requires": { + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "lodash": "^4.17.4" + } + }, + "babel-helper-replace-supers": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helper-replace-supers/download/babel-helper-replace-supers-6.24.1.tgz", + "integrity": "sha1-v22/5Dk40XNpohPKiov3S2qQqxo=", + "dev": true, + "requires": { + "babel-helper-optimise-call-expression": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-helpers": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-helpers/download/babel-helpers-6.24.1.tgz", + "integrity": "sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-messages": { + "version": "6.23.0", + "resolved": "https://registry.npm.taobao.org/babel-messages/download/babel-messages-6.23.0.tgz", + "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-check-es2015-constants": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-check-es2015-constants/download/babel-plugin-check-es2015-constants-6.22.0.tgz", + "integrity": "sha1-NRV7EBQm/S/9PaP3XH0ekYNbv4o=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-external-helpers": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-external-helpers/download/babel-plugin-external-helpers-6.22.0.tgz", + "integrity": "sha1-IoX0iwK9Xe3oUXXK+MYuhq3M76E=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-arrow-functions": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-arrow-functions/download/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz", + "integrity": "sha1-RSaSy3EdX3ncf4XkQM5BufJE0iE=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-block-scoped-functions": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoped-functions/download/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz", + "integrity": "sha1-u8UbSflk1wy42OC5ToICRs46YUE=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-block-scoping": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoping/download/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz", + "integrity": "sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=", + "dev": true, + "requires": { + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "lodash": "^4.17.4" + } + }, + "babel-plugin-transform-es2015-classes": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-classes/download/babel-plugin-transform-es2015-classes-6.24.1.tgz?cache=0&sync_timestamp=1586264294634&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-plugin-transform-es2015-classes%2Fdownload%2Fbabel-plugin-transform-es2015-classes-6.24.1.tgz", + "integrity": "sha1-WkxYpQyclGHlZLSyo7+ryXolhNs=", + "dev": true, + "requires": { + "babel-helper-define-map": "^6.24.1", + "babel-helper-function-name": "^6.24.1", + "babel-helper-optimise-call-expression": "^6.24.1", + "babel-helper-replace-supers": "^6.24.1", + "babel-messages": "^6.23.0", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-computed-properties": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-computed-properties/download/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz", + "integrity": "sha1-b+Ko0WiV1WNPTNmZttNICjCBWbM=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-destructuring": { + "version": "6.23.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-destructuring/download/babel-plugin-transform-es2015-destructuring-6.23.0.tgz", + "integrity": "sha1-mXux8auWf2gtKwh2/jWNYOdlxW0=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-duplicate-keys": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-duplicate-keys/download/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz", + "integrity": "sha1-c+s9MQypaePvnskcU3QabxV2Qj4=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-for-of": { + "version": "6.23.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-for-of/download/babel-plugin-transform-es2015-for-of-6.23.0.tgz", + "integrity": "sha1-9HyVsrYT3x0+zC/bdXNiPHUkhpE=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-function-name": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-function-name/download/babel-plugin-transform-es2015-function-name-6.24.1.tgz", + "integrity": "sha1-g0yJhTvDaxrw86TF26qU/Y6sqos=", + "dev": true, + "requires": { + "babel-helper-function-name": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-literals": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-literals/download/babel-plugin-transform-es2015-literals-6.22.0.tgz", + "integrity": "sha1-T1SgLWzWbPkVKAAZox0xklN3yi4=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-modules-amd": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-amd/download/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz", + "integrity": "sha1-Oz5UAXI5hC1tGcMBHEvS8AoA0VQ=", + "dev": true, + "requires": { + "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-modules-commonjs": { + "version": "6.26.2", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-commonjs/download/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz", + "integrity": "sha1-WKeThjqefKhwvcWogRF/+sJ9tvM=", + "dev": true, + "requires": { + "babel-plugin-transform-strict-mode": "^6.24.1", + "babel-runtime": "^6.26.0", + "babel-template": "^6.26.0", + "babel-types": "^6.26.0" + } + }, + "babel-plugin-transform-es2015-modules-systemjs": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-systemjs/download/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz", + "integrity": "sha1-/4mhQrkRmpBhlfXxBuzzBdlAfSM=", + "dev": true, + "requires": { + "babel-helper-hoist-variables": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-modules-umd": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-umd/download/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz", + "integrity": "sha1-rJl+YoXNGO1hdq22B9YCNErThGg=", + "dev": true, + "requires": { + "babel-plugin-transform-es2015-modules-amd": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-object-super": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-object-super/download/babel-plugin-transform-es2015-object-super-6.24.1.tgz", + "integrity": "sha1-JM72muIcuDp/hgPa0CH1cusnj40=", + "dev": true, + "requires": { + "babel-helper-replace-supers": "^6.24.1", + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-parameters": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-parameters/download/babel-plugin-transform-es2015-parameters-6.24.1.tgz", + "integrity": "sha1-V6w1GrScrxSpfNE7CfZv3wpiXys=", + "dev": true, + "requires": { + "babel-helper-call-delegate": "^6.24.1", + "babel-helper-get-function-arity": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-template": "^6.24.1", + "babel-traverse": "^6.24.1", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-shorthand-properties": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-shorthand-properties/download/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz", + "integrity": "sha1-JPh11nIch2YbvZmkYi5R8U3jiqA=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-spread": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-spread/download/babel-plugin-transform-es2015-spread-6.22.0.tgz", + "integrity": "sha1-1taKmfia7cRTbIGlQujdnxdG+NE=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-sticky-regex": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-sticky-regex/download/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz", + "integrity": "sha1-AMHNsaynERLN8M9hJsLta0V8zbw=", + "dev": true, + "requires": { + "babel-helper-regex": "^6.24.1", + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-plugin-transform-es2015-template-literals": { + "version": "6.22.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-template-literals/download/babel-plugin-transform-es2015-template-literals-6.22.0.tgz", + "integrity": "sha1-qEs0UPfp+PH2g51taH2oS7EjbY0=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-typeof-symbol": { + "version": "6.23.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-typeof-symbol/download/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz", + "integrity": "sha1-3sCfHN3/lLUqxz1QXITfWdzOs3I=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, + "babel-plugin-transform-es2015-unicode-regex": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-es2015-unicode-regex/download/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz", + "integrity": "sha1-04sS9C6nMj9yk4fxinxa4frrNek=", + "dev": true, + "requires": { + "babel-helper-regex": "^6.24.1", + "babel-runtime": "^6.22.0", + "regexpu-core": "^2.0.0" + } + }, + "babel-plugin-transform-regenerator": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-regenerator/download/babel-plugin-transform-regenerator-6.26.0.tgz", + "integrity": "sha1-4HA2lvveJ/Cj78rPi03KL3s6jy8=", + "dev": true, + "requires": { + "regenerator-transform": "^0.10.0" + } + }, + "babel-plugin-transform-strict-mode": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-plugin-transform-strict-mode/download/babel-plugin-transform-strict-mode-6.24.1.tgz", + "integrity": "sha1-1fr3qleKZbvlkc9e2uBKDGcCB1g=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0", + "babel-types": "^6.24.1" + } + }, + "babel-preset-es2015": { + "version": "6.24.1", + "resolved": "https://registry.npm.taobao.org/babel-preset-es2015/download/babel-preset-es2015-6.24.1.tgz?cache=0&sync_timestamp=1586265011710&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-preset-es2015%2Fdownload%2Fbabel-preset-es2015-6.24.1.tgz", + "integrity": "sha1-1EBQ1rwsn+6nAqrzjXJ6AhBTiTk=", + "dev": true, + "requires": { + "babel-plugin-check-es2015-constants": "^6.22.0", + "babel-plugin-transform-es2015-arrow-functions": "^6.22.0", + "babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0", + "babel-plugin-transform-es2015-block-scoping": "^6.24.1", + "babel-plugin-transform-es2015-classes": "^6.24.1", + "babel-plugin-transform-es2015-computed-properties": "^6.24.1", + "babel-plugin-transform-es2015-destructuring": "^6.22.0", + "babel-plugin-transform-es2015-duplicate-keys": "^6.24.1", + "babel-plugin-transform-es2015-for-of": "^6.22.0", + "babel-plugin-transform-es2015-function-name": "^6.24.1", + "babel-plugin-transform-es2015-literals": "^6.22.0", + "babel-plugin-transform-es2015-modules-amd": "^6.24.1", + "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", + "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1", + "babel-plugin-transform-es2015-modules-umd": "^6.24.1", + "babel-plugin-transform-es2015-object-super": "^6.24.1", + "babel-plugin-transform-es2015-parameters": "^6.24.1", + "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1", + "babel-plugin-transform-es2015-spread": "^6.22.0", + "babel-plugin-transform-es2015-sticky-regex": "^6.24.1", + "babel-plugin-transform-es2015-template-literals": "^6.22.0", + "babel-plugin-transform-es2015-typeof-symbol": "^6.22.0", + "babel-plugin-transform-es2015-unicode-regex": "^6.24.1", + "babel-plugin-transform-regenerator": "^6.24.1" + } + }, + "babel-preset-es2015-rollup": { + "version": "3.0.0", + "resolved": "https://registry.npm.taobao.org/babel-preset-es2015-rollup/download/babel-preset-es2015-rollup-3.0.0.tgz", + "integrity": "sha1-hUtj7N4u6YysQOiC9nv88YWx8ko=", + "dev": true, + "requires": { + "babel-plugin-external-helpers": "^6.18.0", + "babel-preset-es2015": "^6.3.13", + "require-relative": "^0.8.7" + } + }, + "babel-register": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-register/download/babel-register-6.26.0.tgz?cache=0&sync_timestamp=1586264318423&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-register%2Fdownload%2Fbabel-register-6.26.0.tgz", + "integrity": "sha1-btAhFz4vy0htestFxgCahW9kcHE=", + "dev": true, + "requires": { + "babel-core": "^6.26.0", + "babel-runtime": "^6.26.0", + "core-js": "^2.5.0", + "home-or-tmp": "^2.0.0", + "lodash": "^4.17.4", + "mkdirp": "^0.5.1", + "source-map-support": "^0.4.15" + } + }, + "babel-runtime": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, + "requires": { + "core-js": "^2.4.0", + "regenerator-runtime": "^0.11.0" + } + }, + "babel-template": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-template/download/babel-template-6.26.0.tgz", + "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", + "dev": true, + "requires": { + "babel-runtime": "^6.26.0", + "babel-traverse": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "lodash": "^4.17.4" + } + }, + "babel-traverse": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-traverse/download/babel-traverse-6.26.0.tgz", + "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", + "dev": true, + "requires": { + "babel-code-frame": "^6.26.0", + "babel-messages": "^6.23.0", + "babel-runtime": "^6.26.0", + "babel-types": "^6.26.0", + "babylon": "^6.18.0", + "debug": "^2.6.8", + "globals": "^9.18.0", + "invariant": "^2.2.2", + "lodash": "^4.17.4" + } + }, + "babel-types": { + "version": "6.26.0", + "resolved": "https://registry.npm.taobao.org/babel-types/download/babel-types-6.26.0.tgz", + "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", + "dev": true, + "requires": { + "babel-runtime": "^6.26.0", + "esutils": "^2.0.2", + "lodash": "^4.17.4", + "to-fast-properties": "^1.0.3" + } + }, + "babylon": { + "version": "6.18.0", + "resolved": "https://registry.npm.taobao.org/babylon/download/babylon-6.18.0.tgz", + "integrity": "sha1-ry87iPpvXB5MY00aD46sT1WzleM=", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npm.taobao.org/brace-expansion/download/brace-expansion-1.1.11.tgz?cache=0&sync_timestamp=1601898189928&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbrace-expansion%2Fdownload%2Fbrace-expansion-1.1.11.tgz", + "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "builtin-modules": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/builtin-modules/download/builtin-modules-2.0.0.tgz?cache=0&sync_timestamp=1608615075258&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbuiltin-modules%2Fdownload%2Fbuiltin-modules-2.0.0.tgz", + "integrity": "sha1-YLfvWuZUa9fe76dLCLYqQ6IyZI4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npm.taobao.org/concat-map/download/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "convert-source-map": { + "version": "1.7.0", + "resolved": "https://registry.npm.taobao.org/convert-source-map/download/convert-source-map-1.7.0.tgz", + "integrity": "sha1-F6LLiC1/d9NJBYXizmxSRCSjpEI=", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + } + }, + "core-js": { + "version": "2.6.12", + "resolved": "https://registry.npm.taobao.org/core-js/download/core-js-2.6.12.tgz?cache=0&sync_timestamp=1611038912958&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcore-js%2Fdownload%2Fcore-js-2.6.12.tgz", + "integrity": "sha1-2TM9+nsGXjR8xWgiGdb2kIWcwuw=", + "dev": true + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz?cache=0&sync_timestamp=1607566512593&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdebug%2Fdownload%2Fdebug-2.6.9.tgz", + "integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "detect-indent": { + "version": "4.0.0", + "resolved": "https://registry.npm.taobao.org/detect-indent/download/detect-indent-4.0.0.tgz", + "integrity": "sha1-920GQ1LN9Docts5hnE7jqUdd4gg=", + "dev": true, + "requires": { + "repeating": "^2.0.0" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz?cache=0&sync_timestamp=1587627107924&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fescape-string-regexp%2Fdownload%2Fescape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "estree-walker": { + "version": "0.2.1", + "resolved": "https://registry.npm.taobao.org/estree-walker/download/estree-walker-0.2.1.tgz", + "integrity": "sha1-va/oCVOD2EFNXcLs9MkXO225QS4=", + "dev": true + }, + "esutils": { + "version": "2.0.3", + "resolved": "https://registry.npm.taobao.org/esutils/download/esutils-2.0.3.tgz", + "integrity": "sha1-dNLrTeC42hKTcRkQ1Qd1ubcQ72Q=", + "dev": true + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npm.taobao.org/function-bind/download/function-bind-1.1.1.tgz", + "integrity": "sha1-pWiZ0+o8m6uHS7l3O3xe3pL0iV0=", + "dev": true + }, + "globals": { + "version": "9.18.0", + "resolved": "https://registry.npm.taobao.org/globals/download/globals-9.18.0.tgz?cache=0&sync_timestamp=1608438408336&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglobals%2Fdownload%2Fglobals-9.18.0.tgz", + "integrity": "sha1-qjiWs+abSH8X4x7SFD1pqOMMLYo=", + "dev": true + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npm.taobao.org/has/download/has-1.0.3.tgz", + "integrity": "sha1-ci18v8H2qoJB8W3YFOAR4fQeh5Y=", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/has-ansi/download/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "home-or-tmp": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/home-or-tmp/download/home-or-tmp-2.0.0.tgz", + "integrity": "sha1-42w/LSyufXRqhX440Y1fMqeILbg=", + "dev": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.1" + } + }, + "invariant": { + "version": "2.2.4", + "resolved": "https://registry.npm.taobao.org/invariant/download/invariant-2.2.4.tgz", + "integrity": "sha1-YQ88ksk1nOHbYW5TgAjSP/NRWOY=", + "dev": true, + "requires": { + "loose-envify": "^1.0.0" + } + }, + "is-core-module": { + "version": "2.2.0", + "resolved": "https://registry.npm.taobao.org/is-core-module/download/is-core-module-2.2.0.tgz?cache=0&sync_timestamp=1606411604323&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-core-module%2Fdownload%2Fis-core-module-2.2.0.tgz", + "integrity": "sha1-lwN+89UiJNhRY/VZeytj2a/tmBo=", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, + "is-finite": { + "version": "1.1.0", + "resolved": "https://registry.npm.taobao.org/is-finite/download/is-finite-1.1.0.tgz", + "integrity": "sha1-kEE1x3+0LAZB1qobzbxNqo2ggvM=", + "dev": true + }, + "is-module": { + "version": "1.0.0", + "resolved": "https://registry.npm.taobao.org/is-module/download/is-module-1.0.0.tgz", + "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "dev": true + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npm.taobao.org/js-tokens/download/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npm.taobao.org/jsesc/download/jsesc-0.5.0.tgz?cache=0&sync_timestamp=1603891175833&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsesc%2Fdownload%2Fjsesc-0.5.0.tgz", + "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", + "dev": true + }, + "json5": { + "version": "0.5.1", + "resolved": "https://registry.npm.taobao.org/json5/download/json5-0.5.1.tgz?cache=0&sync_timestamp=1612146875530&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjson5%2Fdownload%2Fjson5-0.5.1.tgz", + "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=", + "dev": true + }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.20.tgz?cache=0&sync_timestamp=1597336196663&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flodash%2Fdownload%2Flodash-4.17.20.tgz", + "integrity": "sha1-tEqbYpe8tpjxxRo1RaKzs2jVnFI=", + "dev": true + }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npm.taobao.org/loose-envify/download/loose-envify-1.4.0.tgz", + "integrity": "sha1-ce5R+nvkyuwaY4OffmgtgTLTDK8=", + "dev": true, + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, + "magic-string": { + "version": "0.22.5", + "resolved": "https://registry.npm.taobao.org/magic-string/download/magic-string-0.22.5.tgz", + "integrity": "sha1-jpz1r930Q4XB2lvCpqDb0QsDZX4=", + "dev": true, + "requires": { + "vlq": "^0.2.2" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz?cache=0&sync_timestamp=1597044082534&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fminimatch%2Fdownload%2Fminimatch-3.0.4.tgz", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npm.taobao.org/minimist/download/minimist-1.2.5.tgz", + "integrity": "sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=", + "dev": true + }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.5.tgz?cache=0&sync_timestamp=1587535418745&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmkdirp%2Fdownload%2Fmkdirp-0.5.5.tgz", + "integrity": "sha1-2Rzv1i0UNsoPQWIOJRKI1CAJne8=", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz?cache=0&sync_timestamp=1607433816745&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fms%2Fdownload%2Fms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npm.taobao.org/os-homedir/download/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npm.taobao.org/os-tmpdir/download/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npm.taobao.org/path-is-absolute/download/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npm.taobao.org/path-parse/download/path-parse-1.0.6.tgz", + "integrity": "sha1-1i27VnlAXXLEc37FhgDp3c8G0kw=", + "dev": true + }, + "private": { + "version": "0.1.8", + "resolved": "https://registry.npm.taobao.org/private/download/private-0.1.8.tgz", + "integrity": "sha1-I4Hts2ifelPWUxkAYPz4ItLzaP8=", + "dev": true + }, + "regenerate": { + "version": "1.4.2", + "resolved": "https://registry.npm.taobao.org/regenerate/download/regenerate-1.4.2.tgz?cache=0&sync_timestamp=1604218358172&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fregenerate%2Fdownload%2Fregenerate-1.4.2.tgz", + "integrity": "sha1-uTRtiCfo9aMve6KWN9OYtpAUhIo=", + "dev": true + }, + "regenerator-runtime": { + "version": "0.11.1", + "resolved": "https://registry.npm.taobao.org/regenerator-runtime/download/regenerator-runtime-0.11.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fregenerator-runtime%2Fdownload%2Fregenerator-runtime-0.11.1.tgz", + "integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=", + "dev": true + }, + "regenerator-transform": { + "version": "0.10.1", + "resolved": "https://registry.npm.taobao.org/regenerator-transform/download/regenerator-transform-0.10.1.tgz", + "integrity": "sha1-HkmWg3Ix2ot/PPQRTXG1aRoGgN0=", + "dev": true, + "requires": { + "babel-runtime": "^6.18.0", + "babel-types": "^6.19.0", + "private": "^0.1.6" + } + }, + "regexpu-core": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/regexpu-core/download/regexpu-core-2.0.0.tgz?cache=0&sync_timestamp=1600413554352&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fregexpu-core%2Fdownload%2Fregexpu-core-2.0.0.tgz", + "integrity": "sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA=", + "dev": true, + "requires": { + "regenerate": "^1.2.1", + "regjsgen": "^0.2.0", + "regjsparser": "^0.1.4" + } + }, + "regjsgen": { + "version": "0.2.0", + "resolved": "https://registry.npm.taobao.org/regjsgen/download/regjsgen-0.2.0.tgz", + "integrity": "sha1-bAFq3qxVT3WCP+N6wFuS1aTtsfc=", + "dev": true + }, + "regjsparser": { + "version": "0.1.5", + "resolved": "https://registry.npm.taobao.org/regjsparser/download/regjsparser-0.1.5.tgz?cache=0&sync_timestamp=1612023542566&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fregjsparser%2Fdownload%2Fregjsparser-0.1.5.tgz", + "integrity": "sha1-fuj4Tcb6eS0/0K4ijSS9lJ6tIFw=", + "dev": true, + "requires": { + "jsesc": "~0.5.0" + } + }, + "repeating": { + "version": "2.0.1", + "resolved": "https://registry.npm.taobao.org/repeating/download/repeating-2.0.1.tgz", + "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", + "dev": true, + "requires": { + "is-finite": "^1.0.0" + } + }, + "require-relative": { + "version": "0.8.7", + "resolved": "https://registry.npm.taobao.org/require-relative/download/require-relative-0.8.7.tgz", + "integrity": "sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=", + "dev": true + }, + "resolve": { + "version": "1.20.0", + "resolved": "https://registry.npm.taobao.org/resolve/download/resolve-1.20.0.tgz", + "integrity": "sha1-YpoBP7P3B1XW8LeTXMHCxTeLGXU=", + "dev": true, + "requires": { + "is-core-module": "^2.2.0", + "path-parse": "^1.0.6" + } + }, + "rollup": { + "version": "0.41.6", + "resolved": "https://registry.npm.taobao.org/rollup/download/rollup-0.41.6.tgz?cache=0&sync_timestamp=1612505685559&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Frollup%2Fdownload%2Frollup-0.41.6.tgz", + "integrity": "sha1-4NBUl4d6OYwQTYFtJzOnGKepTio=", + "dev": true, + "requires": { + "source-map-support": "^0.4.0" + } + }, + "rollup-plugin-babel": { + "version": "2.7.1", + "resolved": "https://registry.npm.taobao.org/rollup-plugin-babel/download/rollup-plugin-babel-2.7.1.tgz", + "integrity": "sha1-FlKBl7D5OKFTb0RoPHqT1XMYL1c=", + "dev": true, + "requires": { + "babel-core": "6", + "babel-plugin-transform-es2015-classes": "^6.9.0", + "object-assign": "^4.1.0", + "rollup-pluginutils": "^1.5.0" + } + }, + "rollup-plugin-commonjs": { + "version": "8.4.1", + "resolved": "https://registry.npm.taobao.org/rollup-plugin-commonjs/download/rollup-plugin-commonjs-8.4.1.tgz", + "integrity": "sha1-XJzqKyw94yL1+8zRR+B+1eUC16A=", + "dev": true, + "requires": { + "acorn": "^5.2.1", + "estree-walker": "^0.5.0", + "magic-string": "^0.22.4", + "resolve": "^1.4.0", + "rollup-pluginutils": "^2.0.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.5.2", + "resolved": "https://registry.npm.taobao.org/estree-walker/download/estree-walker-0.5.2.tgz", + "integrity": "sha1-04UL51KclYDYFWALUxJlFeFG3Tk=", + "dev": true + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npm.taobao.org/rollup-pluginutils/download/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha1-cvKvB0i1kjZNvTOJ5gDlqURKNR4=", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npm.taobao.org/estree-walker/download/estree-walker-0.6.1.tgz", + "integrity": "sha1-UwSRQ/QMbrkYsjZx0f4yGfOhs2I=", + "dev": true + } + } + } + } + }, + "rollup-plugin-json": { + "version": "2.3.1", + "resolved": "https://registry.npm.taobao.org/rollup-plugin-json/download/rollup-plugin-json-2.3.1.tgz", + "integrity": "sha1-l1nSfzPc0siW3hi2I13xYriO3Xc=", + "dev": true, + "requires": { + "rollup-pluginutils": "^2.0.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npm.taobao.org/estree-walker/download/estree-walker-0.6.1.tgz", + "integrity": "sha1-UwSRQ/QMbrkYsjZx0f4yGfOhs2I=", + "dev": true + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npm.taobao.org/rollup-pluginutils/download/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha1-cvKvB0i1kjZNvTOJ5gDlqURKNR4=", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + } + } + } + }, + "rollup-plugin-node-resolve": { + "version": "3.4.0", + "resolved": "https://registry.npm.taobao.org/rollup-plugin-node-resolve/download/rollup-plugin-node-resolve-3.4.0.tgz", + "integrity": "sha1-kIWF7aEuOTyqx0mHFaAeCGBqvIk=", + "dev": true, + "requires": { + "builtin-modules": "^2.0.0", + "is-module": "^1.0.0", + "resolve": "^1.1.6" + } + }, + "rollup-pluginutils": { + "version": "1.5.2", + "resolved": "https://registry.npm.taobao.org/rollup-pluginutils/download/rollup-pluginutils-1.5.2.tgz", + "integrity": "sha1-HhVud4+UtyVb+hs9AXi+j1xVJAg=", + "dev": true, + "requires": { + "estree-walker": "^0.2.1", + "minimatch": "^3.0.2" + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz", + "integrity": "sha1-mR7GnSluAxN0fVm9/St0XDX4go0=", + "dev": true + }, + "slash": { + "version": "1.0.0", + "resolved": "https://registry.npm.taobao.org/slash/download/slash-1.0.0.tgz", + "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npm.taobao.org/source-map/download/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + }, + "source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npm.taobao.org/source-map-support/download/source-map-support-0.4.18.tgz?cache=0&sync_timestamp=1594041775834&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsource-map-support%2Fdownload%2Fsource-map-support-0.4.18.tgz", + "integrity": "sha1-Aoam3ovkJkEzhZTpfM6nXwosWF8=", + "dev": true, + "requires": { + "source-map": "^0.5.6" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npm.taobao.org/strip-ansi/download/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-2.0.0.tgz?cache=0&sync_timestamp=1611394023277&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "to-fast-properties": { + "version": "1.0.3", + "resolved": "https://registry.npm.taobao.org/to-fast-properties/download/to-fast-properties-1.0.3.tgz", + "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=", + "dev": true + }, + "trim-right": { + "version": "1.0.1", + "resolved": "https://registry.npm.taobao.org/trim-right/download/trim-right-1.0.1.tgz", + "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", + "dev": true + }, + "vlq": { + "version": "0.2.3", + "resolved": "https://registry.npm.taobao.org/vlq/download/vlq-0.2.3.tgz", + "integrity": "sha1-jz5DKM9jsVQMDWfhsneDhviXWyY=", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..2df7e0d --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "vuedev", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "rollup --config" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "babel-preset-es2015-rollup": "^3.0.0", + "rollup": "^0.41.6", + "rollup-plugin-babel": "^2.7.1", + "rollup-plugin-commonjs": "^8.0.2", + "rollup-plugin-json": "^2.3.0", + "rollup-plugin-node-resolve": "^3.0.0" + } +} diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..c4bd766 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,22 @@ +import babel from 'rollup-plugin-babel'; +import resolve from 'rollup-plugin-node-resolve'; +import commonjs from 'rollup-plugin-commonjs'; +import json from 'rollup-plugin-json'; + +export default { + entry: 'src/entry-dev.js', + moduleName: 'Pvue', + format: 'umd', + dest: 'dist/vue.js', + plugins: [ + resolve({ + browser: true, + }), + json(), + commonjs(), + babel({ + exclude: 'node_modules/**', + }), + ], + sourceMap: true, +}; \ No newline at end of file diff --git a/src/array.js b/src/array.js new file mode 100644 index 0000000..8552b52 --- /dev/null +++ b/src/array.js @@ -0,0 +1,40 @@ +/** + * 数组函数劫持 + */ + +import {def} from "./util" + +const arrayProto = Array.prototype + +export const arrayMethods = Object.create(arrayProto) + +const methodsToPatch = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"] + +methodsToPatch.forEach(function (method) { + // 保存原始方法 + const original = arrayProto[method] + // 覆盖之 + def(arrayMethods, method, function (...args) { + // 1.执行默认方法 + const result = original.apply(this, args) + // 2.变更通知 + const ob = this.__ob__ + // 可能会有新元素加入 + let inserted + switch (method) { + case 'push': + case 'unshift': + inserted = args + break + case 'splice': + inserted = args.slice(2) + break + } + // 对新加入的元素做响应式 + if (inserted) ob.observeArray(inserted) + // notify change + // ob内部有一个dep,让它去通知更新 + ob.dep.notify() + return result + }) +}) diff --git a/src/compile.js b/src/compile.js new file mode 100644 index 0000000..ba48c27 --- /dev/null +++ b/src/compile.js @@ -0,0 +1,118 @@ +/** + * 编译器 + */ + +import { Watcher } from './watcher' +import { getDataVal, setDataVal } from './util' + +export class Compile { + constructor(el, vm) { + this.$vm = vm; + this.$el = document.querySelector(el); + if(this.$el) { + this.compile(this.$el); + } + } + + // 递归子节点 + compile(el) { + const childNodes = el.childNodes; + childNodes.forEach(node => { + if(node.nodeType === 1) { // 元素节点 + this.compileElement(node); + // 递归 + if(node.hasChildNodes) { + this.compile(node); + } + } else if (this.isInter(node)) { // {{}} + this.compileText(node); + } + }) + } + + // 正则 {{counter}} + isInter(node) { + return node.nodeType === 3 && /\{\{(.*)\}\}/.test(node.textContent); + } + + // 编译属性 + compileElement(node) { + let nodeAttrs = node.attributes; + Array.from(nodeAttrs).forEach(attr => { + // v-text="xxx" + const attrname = attr.name; // v-text + const exp = attr.value; // xxx + // 指令解析 + if(attrname.indexOf("v-") === 0) { + const dir = attrname.substring(2); + const dirArr = dir.split(':') + if(dirArr.length === 2 && dirArr[0] === 'on') { // 判断 v-on:click ="onclick" + this.eventHandler(node, exp, dirArr[1]) + } else { + this[dir] && this[dir](node, exp) + } + } else if (attrname.indexOf("@") === 0) { // 判断 @click ="onclick" + const dir = attrname.substring(1); + this.eventHandler(node, exp, dir) + } + }) + } + + // 事件处理 + eventHandler(node, exp, event) { + const fn = this.$vm[exp] + if(event && fn) { + node.addEventListener(event, fn.bind(this.$vm), false); + } + } + + // 处理文本节点 + compileText(node) { + this.update(node, RegExp.$1, 'text'); + } + + + // 更新中转函数 + update(node, exp, dir) { + const fn = this[`${dir}Updater`]; + fn && fn(node, getDataVal.call(this.$vm, exp)); + // 依赖wather初始化 + new Watcher(this.$vm, exp, val => { + fn && fn(node, val) + }) + } + + // v-model + modelUpdater(node, value) { + node.value = value + } + + // 文本节点 + textUpdater(node, value) { + node.textContent = value; + } + + // html标签解析节点 + htmlUpdater(node, value) { + node.innerHTML = value; + } + + // v-model + model(node, exp) { + this.update(node, exp, 'model'); + node.addEventListener('input', e => { + setDataVal.call(this.$vm, exp, e.target.value) + }) + } + + // v-text + text(node, exp) { + this.update(node, exp, 'text') + } + + // v-html + html(node, exp) { + this.update(node, exp, 'html') + } + +} diff --git a/src/dep.js b/src/dep.js new file mode 100644 index 0000000..082265b --- /dev/null +++ b/src/dep.js @@ -0,0 +1,27 @@ +/** + * 消息管理器 + */ + +export class Dep { + constructor() { + this.deps = new Set(); + } + + // 添加订阅者 + addSub(watcher) { + this.deps.add(watcher); + } + + // 操作watcher addDep 方法 + depend () { + if (Dep.target) { + Dep.target.addDep(this) + } + } + + // 通知更新 + notify() { + this.deps.forEach(watcher => watcher.update()); + } + +} \ No newline at end of file diff --git a/src/entry-dev.js b/src/entry-dev.js new file mode 100644 index 0000000..2266f63 --- /dev/null +++ b/src/entry-dev.js @@ -0,0 +1,146 @@ +/** + * 入口文件 +*/ + +import { observe, proxy } from './observer.js' +import { Compile } from './compile' +import { Watcher } from './watcher' + +export default class Pvue { + constructor(options) { + this.$options = options; + this.$data = options.data; + observe(this.$data) + + // 代理data + proxy(this) + + // 代理methods + for(const key in options.methods) { + this[key] = typeof options.methods[key] === 'function'? options.methods[key].bind(this): noop; + } + + // 模板编译 + // new Compile(options.el, this) + if(options.el) { + this.$mount(options.el); + } + } + + // 挂载 + $mount(el){ + // 获取宿主原始 + this.$el = document.querySelector(el); + // 组件更新函数 + const updateComponent = () => { + const { render } = this.$options; + const vnode = render.call(this, this.$createElement); + this._update(vnode); + + } + // 创建wather + new Watcher(this, updateComponent); + } + + // 获取vnode + $createElement(tag, props, children) { + return { tag, props, children }; + } + // 更新 + _update(vnode) { + const preVnode = this._vnode; + if(preVnode) { // 更新 + this.__patch__(preVnode, vnode) + } else { // 初始化 + this.__patch__(this.$el, vnode) + } + } + // patch方法 + __patch__(oldVode, vnode){ + // 判断old是否为dom + if(oldVode.nodeType) { // 初始化 + const parent = oldVode.parentElement; + const refElm = oldVode.nextSibling; + // 递归vnode创建dom树 + const el = this.createElm(vnode); + parent.insertBefore(el, refElm); + parent.removeChild(oldVode); + } else { // 更新 + const el = vnode.el = oldVode.el; + // 判断是否是相同节点samenode + if(oldVode.tag === vnode.tag) { + // diff + // props + // children + const oldCh = oldVode.children; + const newCh = vnode.children; + if(typeof newCh === 'string') { + if(typeof oldCh === 'string') { + if(newCh !== oldCh) { + el.textContent = newCh; + } + } else { + // 清空并替换为文本 + el.textContent = newCh; + } + } else { + // 数组 + if(typeof oldCh === 'string') { + el.innerHTML = ''; + newCh.forEach(child => { + el.appendChild(this.createElm(child)); + }) + } else { // 双方都有孩子 diff + this.updateChildren(el, oldCh, newCh); + } + } + } + } + // 保存vnode + this._vnode = vnode; + + } + // 创建真实节点 + createElm(vnode) { + const el = document.createElement(vnode.tag); + // props + for (const key in vnode.props) { + el.setAttribute(key, vnode.props[key]); + } + + // 处理子节点 + if(vnode.children) { + if(typeof vnode.children !== 'object') { + el.textContent = vnode.children; + } else { + // 数组类子元素 + vnode.children.forEach(vnode => { + el.appendChild(this.createElm(vnode)); + }) + } + } + vnode.el = el; + return el; + } + // 更新子元素 + updateChildren(parentElm, oldCh, newCh){ + const len = Math.min(oldCh.length, newCh.length); + // 强制更新,不管节点是否相同 + for(let i=0; i newCh.length) { // 删除 + oldCh.slice(len).forEach(child => { + parentElm.removeChild(child.el); + }) + } else { // 追加 + newCh.slice(len).forEach(child => { + const el = this.createElm(child); + parentElm.appendChild(el); + }) + } + } +} + +// 空函数 +function noop(){} \ No newline at end of file diff --git a/src/observer.js b/src/observer.js new file mode 100644 index 0000000..bcfc267 --- /dev/null +++ b/src/observer.js @@ -0,0 +1,95 @@ +/** + * 响应式数据 + */ + +import { Dep } from './dep' +import { arrayMethods } from './array' +import { def, hasOwn, dependArray } from './util' + +export class Observer { + constructor(value) { + this.value = value; + this.dep = new Dep() + def(value, '__ob__', this) + if(Array.isArray(value)) { + if('__proto__' in {}) { + value.__proto__ = arrayMethods; + } + this.observeArray(value) + } else { + this.walk(value) + } + } + + // 数组响应式处理 + observeArray(arr) { + for(let i=0, l = arr.length; i { + defineReactive(obj, key, obj[key]); + }) + } +} + +// 数据劫持 +export function defineReactive(obj, key, val){ + let childOb = observe(val); + // 每一可以对应一个 dep; + const dep = new Dep(); + Object.defineProperty(obj, key, { + get() { + // 依赖收集 + dep.depend(); + if (childOb) { + // 子ob也要做依赖收集 + childOb.dep.depend() + if (Array.isArray(val)) { + dependArray(val) + } + } + return val; + }, + set(newVal) { + if(val !== newVal) { + observe(newVal); + val = newVal; + // 通知更新 + dep.notify(); + } + } + }) +} + +// observe +export function observe(obj) { + if(typeof obj !== 'object' || obj === null) { + return; + } + let ob; + if(hasOwn(obj, '__ob__') && obj.__ob__ instanceof Observer) { + ob = obj.__ob__ + } else { + ob = new Observer(obj); + } + return ob; +} + +// porxy +export function proxy(vm) { + Object.keys(vm.$data).forEach(key => { + Object.defineProperty(vm, key, { + get() { + return vm.$data[key] + }, + set(newVal) { + vm.$data[key] = newVal; + } + }) + }) +} + diff --git a/src/patch.js b/src/patch.js new file mode 100644 index 0000000..d63b702 --- /dev/null +++ b/src/patch.js @@ -0,0 +1,3 @@ +/** + * patch函数部分的实现 + */ diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..f7cbb84 --- /dev/null +++ b/src/util.js @@ -0,0 +1,61 @@ +// 返回指定 key 对应的 data值 +export function getDataVal(exp) { + let value + if(/\[|\|]|\./.test(exp)) { + let keyArr = exp.replace(/\]/g, '').split(/\[|\./g); + keyArr.forEach((key, index) => { + value = index === 0? this[key]: value[key]; + }) + } else { + value = this[exp] + } + return value; +} + +// 设置指定 key 对应的 data值 +export function setDataVal(exp, value) { + let val + if(/\[|\|]|\./.test(exp)) { + let keyArr = exp.replace(/\]/g, '').split(/\[|\./g); + let l = keyArr.length -1 ; + keyArr.forEach((key, index) => { + if(index === 0) { + val = this[key] + } else if (index === l){ + val[key] = value + } else { + val = val[key] + } + }) + } else { + this[exp] = value + } +} + + +// 定义一个Property +export function def(obj, key, val, enumerable) { + Object.defineProperty(obj, key, { + value: val, + enumerable: !!enumerable, + writable: true, + configurable: true + }) +} + +// 数组响应式处理 +export function dependArray (value) { + for (let e, i = 0, l = value.length; i < l; i++) { + e = value[i] + e && e.__ob__ && e.__ob__.dep.depend() + if (Array.isArray(e)) { + dependArray(e) + } + } +} + +// 检测一个对象的属性是否存在 +const hasOwnProperty = Object.prototype.hasOwnProperty; +export function hasOwn(obj, key){ + return hasOwnProperty.call(obj, key) +} diff --git a/src/watcher.js b/src/watcher.js new file mode 100644 index 0000000..0be78b7 --- /dev/null +++ b/src/watcher.js @@ -0,0 +1,33 @@ +/** + * 依赖收集 + */ + +import { Dep } from "./dep"; +import { getDataVal } from "./util" + +export class Watcher { + constructor(vm, updaterFn) { + this.vm = vm; + this.getter = updaterFn; + + // 依赖收集 + this.get(); + } + + get() { + Dep.target = this; + this.getter.call(this.vm); + Dep.target = null; + } + + // 相互添加引用 + addDep (dep) { + dep.addSub(this) + } + + update() { + this.get(); + // this.updaterFn.call(this.vm, getDataVal.call(this.vm, this.key)) + } + +} \ No newline at end of file -- Gitee