Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 11, 2016
0 parents commit a879ec0
Show file tree
Hide file tree
Showing 35 changed files with 3,671 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"development": {
"presets": ["es2015", "stage-2"]
},
"production": {
"presets": ["es2015-rollup", "stage-2"]
}
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
node_modules
npm-debug.log
explorations
TODOs.md
124 changes: 124 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
var fs = require('fs')
var zlib = require('zlib')
var rollup = require('rollup')
var uglify = require('uglify-js')
var babel = require('rollup-plugin-babel')
var node = require('rollup-plugin-node-resolve')
var commonjs = require('rollup-plugin-commonjs')
var replace = require('rollup-plugin-replace')
var version = process.env.VERSION || require('../package.json').version

var banner =
'/*!\n' +
' * Vue.js v' + version + '\n' +
' * (c) ' + new Date().getFullYear() + ' Evan You\n' +
' * Released under the MIT License.\n' +
' */'

// update main file
var main = fs
.readFileSync('src/index.js', 'utf-8')
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
fs.writeFileSync('src/index.js', main)

var plugins = [
node(),
commonjs({
include: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
})
]

// CommonJS build.
// this is used as the "main" field in package.json
// and used by bundlers like Webpack and Browserify.
rollup.rollup({
entry: 'src/index.js',
plugins: plugins
})
.then(function (bundle) {
return write('dist/vue.common.js', bundle.generate({
format: 'cjs',
banner: banner
}).code)
})
// Standalone Dev Build
.then(function () {
return rollup.rollup({
entry: 'src/index.js',
plugins: [
replace({
'process.env.NODE_ENV': "'development'"
})
].concat(plugins)
})
.then(function (bundle) {
return write('dist/vue.js', bundle.generate({
format: 'umd',
banner: banner,
moduleName: 'Vue'
}).code)
})
})
.then(function () {
// Standalone Production Build
return rollup.rollup({
entry: 'src/index.js',
plugins: [
replace({
'process.env.NODE_ENV': "'production'"
})
].concat(plugins)
})
.then(function (bundle) {
var code = bundle.generate({
format: 'umd',
moduleName: 'Vue'
}).code
var minified = banner + '\n' + uglify.minify(code, {
fromString: true,
output: {
ascii_only: true
}
}).code
return write('dist/vue.min.js', minified)
})
.then(zip)
})
.catch(logError)

function write (dest, code) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve()
})
})
}

function zip () {
return new Promise(function (resolve, reject) {
fs.readFile('dist/vue.min.js', function (err, buf) {
if (err) return reject(err)
zlib.gzip(buf, function (err, buf) {
if (err) return reject(err)
write('dist/vue.min.js.gz', buf).then(resolve)
})
})
})
}

function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}

function logError (e) {
console.log(e)
}

function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "vue-lite",
"version": "1.0.0",
"description": "Lighter-weight Vue on virtual dom",
"main": "index.js",
"scripts": {
"dev": "webpack --watch",
"test": "mocha",
"build": "NODE_ENV=production node build/build.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vue-lite.git"
},
"keywords": [
"vue"
],
"author": "Evan You",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/vue-lite/issues"
},
"homepage": "https://github.com/vuejs/vue-lite#readme",
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-preset-stage-2": "^6.0.0",
"rollup": "^0.25.8",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-commonjs": "^2.2.1",
"rollup-plugin-node-resolve": "^1.5.0",
"rollup-plugin-replace": "^1.1.0",
"uglify-js": "^2.6.2",
"webpack": "^1.12.14"
}
}
129 changes: 129 additions & 0 deletions src/compiler/codegen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { parseText } from './text-parser'

const bindRE = /^:|^v-bind:/
const onRE = /^@|^v-on:/
const mustUsePropsRE = /^(value|selected|checked|muted)$/

export function generate (ast) {
const code = genElement(ast)
return new Function (`with (this) { return ${code}}`)
}

function genElement (el, key) {
let exp
if (exp = getAttr(el, 'v-for')) {
return genFor(el, exp)
} else if (exp = getAttr(el, 'v-if')) {
return genIf(el, exp)
} else if (el.tag === 'template') {
return genChildren(el)
} else {
return `__h__('${ el.tag }', ${ genData(el, key) }, ${ genChildren(el) })`
}
}

function genIf (el, exp) {
return `(${ exp }) ? ${ genElement(el) } : ''`
}

function genFor (el, exp) {
const inMatch = exp.match(/([a-zA-Z_][\w]*)\s+(?:in|of)\s+(.*)/)
if (!inMatch) {
throw new Error('Invalid v-for expression: '+ exp)
}
const alias = inMatch[1].trim()
exp = inMatch[2].trim()
const key = el.attrsMap['track-by'] || 'undefined'
return `(${ exp }).map(function (${ alias }, $index) {return ${ genElement(el, key) }})`
}

function genData (el, key) {
if (!el.attrs.length) {
return '{}'
}
let data = key ? `{key:${ key },` : `{`
if (el.attrsMap[':class'] || el.attrsMap['class']) {
data += `class: _renderClass(${ el.attrsMap[':class'] }, "${ el.attrsMap['class'] || '' }"),`
}
let attrs = `attrs:{`
let props = `props:{`
let hasAttrs = false
let hasProps = false
for (let i = 0, l = el.attrs.length; i < l; i++) {
let attr = el.attrs[i]
let name = attr.name
if (bindRE.test(name)) {
name = name.replace(bindRE, '')
if (name === 'class') {
continue
} else if (name === 'style') {
data += `style: ${ attr.value },`
} else if (mustUsePropsRE.test(name)) {
hasProps = true
props += `"${ name }": (${ attr.value }),`
} else {
hasAttrs = true
attrs += `"${ name }": (${ attr.value }),`
}
} else if (onRE.test(name)) {
name = name.replace(onRE, '')
// TODO
} else if (name !== 'class') {
hasAttrs = true
attrs += `"${ name }": (${ JSON.stringify(attr.value) }),`
}
}
if (hasAttrs) {
data += attrs.slice(0, -1) + '},'
}
if (hasProps) {
data += props.slice(0, -1) + '},'
}
return data.replace(/,$/, '') + '}'
}

function genChildren (el) {
if (!el.children.length) {
return 'undefined'
}
return '__flatten__([' + el.children.map(genNode).join(',') + '])'
}

function genNode (node) {
if (node.tag) {
return genElement(node)
} else {
return genText(node)
}
}

function genText (text) {
if (text === ' ') {
return '" "'
} else {
const exp = parseText(text)
if (exp) {
return 'String(' + escapeNewlines(exp) + ')'
} else {
return escapeNewlines(JSON.stringify(text))
}
}
}

function escapeNewlines (str) {
return str.replace(/\n/g, '\\n')
}

function getAttr (el, attr) {
let val
if (val = el.attrsMap[attr]) {
el.attrsMap[attr] = null
for (let i = 0, l = el.attrs.length; i < l; i++) {
if (el.attrs[i].name === attr) {
el.attrs.splice(i, 1)
break
}
}
}
return val
}
Loading

24 comments on commit a879ec0

@vyaron
Copy link

@vyaron vyaron commented on a879ec0 Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@Rainmen-xia
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@wufeicris
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

终于找到第一个commit

@bestanan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect!!

@enbermudas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beginning!

@PurpleDandelion
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first commit

@jasonliao001
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tue Oct 08 2019 15:39:22

@ucooling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will start learn from this commit

@Justin609356072
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jocstech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在此膜拜前端大神尤雨溪

@aaronlamz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从第一个commit开始学习😄

@O-AN-drew-O
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

观摩大神的第一个commit

@phpjsnerd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where it all started. The origin story of vue.js.

@xiaoningtongxue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

来到这里彷佛穿越时空回到过去了

@feiyuerenhai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the commit number in the url navigate us to the start of everything.

@zeayal
Copy link

@zeayal zeayal commented on a879ec0 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v3.0.0 One Piece

@leyiang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实不算是第一个Commit,branch 为 0.10 的才是。

@zyzweb
Copy link

@zyzweb zyzweb commented on a879ec0 Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

@dingdaofeng
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job

@m4heshd
Copy link

@m4heshd m4heshd commented on a879ec0 Jun 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a migration. Where's the original repo?

@0fatihyildiz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ben kaldım kardeşş

@GLFei
Copy link

@GLFei GLFei commented on a879ec0 May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello vue

@yukihim
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Baby vue

@khalidbelk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came here with FirstCommitter ❤️

Please sign in to comment.