Skip to content

Commit 926c955

Browse files
authored
Merge pull request #3 from peakchen90/dev
Dev
2 parents 3187a67 + 70be3cd commit 926c955

File tree

118 files changed

+674
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+674
-301
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules
22
test/coverage
33
test/unit/fixtures
4-
lib
4+
runtime
55
*.d.ts

.travis.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
language: node_js
22

3+
os:
4+
- linux
5+
36
node_js:
4-
- "8.6.0"
7+
- "11"
8+
- "12"
9+
- "13"
510

611
install:
712
- npm install
813
- npm run test:install
914
- npm install -g codecov
1015

11-
script:
12-
- npm run test
13-
- codecov
16+
stages:
17+
- test
18+
- name: deploy
19+
if: branch = master
20+
21+
jobs:
22+
include:
23+
- stage: test
24+
name: "Run test scripts"
25+
node_js: "8.6.0"
26+
script:
27+
- npm run test
28+
- codecov
29+
30+
- stage: deploy
31+
name: "Release npm package"
32+
node_js: "8.6.0"
33+
script: echo "Deploying to npm ..."
34+
deploy:
35+
provider: npm
36+
37+
api_key: "$NPM_TOKEN"
38+
on:
39+
branch: master
1440

1541
notifications:
1642
email: false

lib/runtime.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

package-lock.json

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@
4141
"babel-plugin",
4242
"react-directive",
4343
"jsx-directive",
44+
"jsx-plus",
4445
"directive",
4546
"react",
4647
"vue",
4748
"x-if",
48-
"v-if"
49+
"x-for",
50+
"v-if",
51+
"v-for"
4952
],
5053
"engines": {
5154
"node": ">=8.6.0"
5255
},
5356
"dependencies": {
5457
"@babel/code-frame": "^7.5.5",
5558
"@babel/generator": "^7.6.4",
56-
"@babel/template": "^7.6.0",
5759
"@babel/types": "^7.6.1",
60+
"ajv": "^6.10.2",
61+
"ajv-errors": "^1.0.1",
5862
"chalk": "^2.4.2",
5963
"semver": "^6.3.0"
6064
},

runtime/classnames.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*!
2+
Copyright (c) 2018 Jed Watson.
3+
Licensed under the MIT License (MIT), see
4+
http://jedwatson.github.io/classnames
5+
*/
6+
7+
var hasOwn = {}.hasOwnProperty;
8+
9+
function classNames () {
10+
var classes = [];
11+
12+
for (var i = 0; i < arguments.length; i++) {
13+
var arg = arguments[i];
14+
if (!arg) continue;
15+
16+
var argType = typeof arg;
17+
18+
if (argType === 'string' || argType === 'number') {
19+
classes.push(arg);
20+
} else if (Array.isArray(arg) && arg.length) {
21+
var inner = classNames.apply(null, arg);
22+
if (inner) {
23+
classes.push(inner);
24+
}
25+
} else if (argType === 'object') {
26+
for (var key in arg) {
27+
if (hasOwn.call(arg, key) && arg[key]) {
28+
classes.push(key);
29+
}
30+
}
31+
}
32+
}
33+
34+
return classes.join(' ');
35+
}
36+
37+
module.exports = classNames;

runtime/invoke-onchange.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var mergeProps = require('./merge-props.js');
2+
3+
function invokeOnchange(args, items) {
4+
var onChange = mergeProps('onChange', items);
5+
6+
if (typeof onChange === 'function') {
7+
onChange.apply(this, args);
8+
}
9+
}
10+
11+
module.exports = invokeOnchange;

runtime/merge-props.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function mergeProps(prop, items) {
2+
var result;
3+
for (var i = 0; i < items.length; i++) {
4+
var item = items[i];
5+
if (item && typeof item === 'object' && (prop in item)) {
6+
result = item[prop];
7+
}
8+
}
9+
return result;
10+
}
11+
12+
module.exports = mergeProps;

runtime/resolve-value.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function resolveValue(args) {
2+
return args[0] && args[0].target && typeof args[0].target === 'object'
3+
? args[0].target.value
4+
: args[0];
5+
}
6+
7+
module.exports = resolveValue;

src/directives/class.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const t = require('@babel/types');
2+
const { DIRECTIVES } = require('../shared');
3+
const attrUtil = require('../utils/attribute');
4+
const elemUtil = require('../utils/element');
5+
const builder = require('../utils/builder');
6+
const { codeFrameWarn } = require('../utils/util');
7+
8+
/**
9+
* 转换className
10+
* @param path
11+
*/
12+
function transformClass(path) {
13+
const attrPath = elemUtil(path).findAttrPath(DIRECTIVES.CLASS);
14+
if (!attrPath) {
15+
return;
16+
}
17+
18+
const bindingValue = attrUtil(attrPath).valueExpr();
19+
20+
/* istanbul ignore next: print warn info */
21+
if (!bindingValue) {
22+
codeFrameWarn(
23+
attrPath,
24+
`\`${DIRECTIVES.CLASS}\` used on element <${elemUtil(path).name()}> without binding value`
25+
);
26+
attrPath.remove();
27+
return;
28+
}
29+
30+
// 设置 `className` prop
31+
elemUtil(path).mergeProps({
32+
prop: 'className',
33+
34+
directivePath: attrPath,
35+
36+
find(attr, setValue) {
37+
const attrName = attrUtil(attr).name();
38+
const valueExpr = attrUtil(attr).valueExpr();
39+
40+
if (attrName === 'className') {
41+
setValue(t.objectExpression([
42+
t.objectProperty(
43+
t.identifier('className'),
44+
valueExpr
45+
)
46+
]));
47+
48+
return true;
49+
}
50+
51+
return false;
52+
},
53+
54+
getResult(mergeItems) {
55+
if (mergeItems.length > 0) {
56+
return builder.buildCallRuntimeExpression(
57+
'classnames.js',
58+
[
59+
t.arrayExpression([
60+
mergeItems.length > 0 && builder.buildCallRuntimeExpression(
61+
'merge-props.js',
62+
[
63+
t.stringLiteral('className'),
64+
t.arrayExpression(mergeItems)
65+
],
66+
t.thisExpression()
67+
),
68+
bindingValue
69+
].filter(Boolean))
70+
]
71+
);
72+
}
73+
74+
return builder.buildCallRuntimeExpression(
75+
'classnames.js',
76+
[bindingValue]
77+
);
78+
},
79+
});
80+
81+
attrPath.remove();
82+
}
83+
84+
module.exports = transformClass;

0 commit comments

Comments
 (0)