This repository was archived by the owner on Aug 24, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +526
-385
lines changed
Expand file tree Collapse file tree 8 files changed +526
-385
lines changed Original file line number Diff line number Diff line change 55 - 8
66
77before_install :
8- - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.28.4
8+ - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.3.2
99 - export PATH="$HOME/.yarn/bin:$PATH"
1010
1111script :
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1515 "devDependencies" : {
1616 "babel-cli" : " ^6.26.0" ,
1717 "babel-core" : " ^6.26.0" ,
18- "babel-eslint" : " ^7.2 .3" ,
18+ "babel-eslint" : " ^8.0 .3" ,
1919 "babel-plugin-transform-class-properties" : " ^6.24.1" ,
2020 "babel-plugin-transform-object-rest-spread" : " ^6.26.0" ,
2121 "babel-preset-env" : " ^1.6.0" ,
2222 "chalk" : " ^2.1.0" ,
23- "codecov" : " ^2.3 .0" ,
24- "eslint" : " ^4.4 .1" ,
25- "eslint-config-airbnb-base" : " ^11.3.1 " ,
26- "eslint-config-prettier" : " ^2.3 .0" ,
23+ "codecov" : " ^3.0 .0" ,
24+ "eslint" : " ^4.12 .1" ,
25+ "eslint-config-airbnb-base" : " ^12.1.0 " ,
26+ "eslint-config-prettier" : " ^2.9 .0" ,
2727 "eslint-plugin-import" : " ^2.7.0" ,
2828 "glob" : " ^7.1.2" ,
29- "jest" : " ^20.0.4 " ,
30- "lerna" : " ^2.1.0 " ,
31- "lerna-tools" : " ^0.0.2 " ,
29+ "jest" : " ^21.2.1 " ,
30+ "lerna" : " ^2.5.1 " ,
31+ "lerna-tools" : " ^0.0.3 " ,
3232 "micromatch" : " ^3.0.4" ,
3333 "mkdirp" : " ^0.5.1" ,
34+ "prettier" : " ^1.9.1" ,
3435 "string-length" : " ^2.0.0"
3536 },
3637 "workspaces" : [
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import parse from 'h2x-parse'
33import generate from 'h2x-generate'
44import traverse from 'h2x-traverse'
55
6-
76const reduceVisitors = ( visitors , opts ) => {
87 Object . keys ( visitors ) . forEach ( key => {
98 const visitor = visitors [ key ]
@@ -31,9 +30,9 @@ const mergePlugins = plugins =>
3130
3231export { traverse , generate }
3332
34- export function transform ( code , { plugins = [ ] } = { } ) {
33+ export function transform ( code , { plugins = [ ] , state = { } } = { } ) {
3534 const ast = parse ( code )
3635 const { visitor, generator } = mergePlugins ( plugins )
37- traverse ( ast , visitor )
36+ traverse ( ast , visitor , state )
3837 return generate ( ast , generator )
3938}
Original file line number Diff line number Diff line change @@ -31,4 +31,37 @@ describe('transform', () => {
3131 const result = transform ( code , { plugins : [ simpleJsx ] } )
3232 expect ( result ) . toBe ( `<div />\n` )
3333 } )
34+
35+ it ( 'should support state' , ( ) => {
36+ class JSXNode {
37+ static [ NODE_TYPE ] = 'JSXElement'
38+
39+ constructor ( name ) {
40+ this . name = name
41+ }
42+ }
43+
44+ const simpleJsx = ( ) => ( {
45+ visitor : {
46+ HTMLElement : {
47+ enter ( path , state ) {
48+ state . tags . push ( path . node . tagName )
49+ path . replace ( new JSXNode ( 'div' ) )
50+ } ,
51+ } ,
52+ } ,
53+ generator : {
54+ JSXElement : {
55+ enter ( path , generator ) {
56+ generator . writeLine ( `<${ path . node . name } />` )
57+ } ,
58+ } ,
59+ } ,
60+ } )
61+ const state = { tags : [ ] }
62+ const code = `<div></div>`
63+ const result = transform ( code , { plugins : [ simpleJsx ] , state } )
64+ expect ( result ) . toBe ( `<div />\n` )
65+ expect ( state . tags ) . toEqual ( [ 'DIV' ] )
66+ } )
3467} )
Original file line number Diff line number Diff line change 55 * @returns {boolean }
66 */
77export function isNumeric ( value ) {
8- return ! isNaN ( value - parseFloat ( value ) )
8+ return ! Number . isNaN ( value - parseFloat ( value ) )
99}
1010
1111/**
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ class NodePath {
4040 }
4141
4242 call ( key ) {
43- const opts = this . opts
43+ const { opts } = this
4444
4545 if ( this . node ) {
4646 if ( this . _call ( opts [ key ] ) ) return true
@@ -90,7 +90,7 @@ class NodePath {
9090 for ( const fn of fns ) {
9191 if ( ! fn ) continue
9292
93- const node = this . node
93+ const { node } = this
9494 if ( ! node ) return true
9595
9696 const ret = fn ( this , this . state )
You can’t perform that action at this time.
0 commit comments