From 9d0b4f9cf930bc789c5a6e7f90b282e7ba4ede24 Mon Sep 17 00:00:00 2001 From: mar Date: Fri, 28 Jul 2017 12:13:55 +0000 Subject: [PATCH 1/4] fix: `build:browser` failed because of regression in `vlq@0.2.2` --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 39b96490..9b89ff7c 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "acorn-jsx": "^3.0.1", "acorn-object-spread": "^1.0.0", "chalk": "^1.1.3", + "vlq": "0.2.1", "magic-string": "^0.14.0", "minimist": "^1.2.0", "os-homedir": "^1.0.1" From cb3d6c1d4514fc9a3c32df243e942e808d358725 Mon Sep 17 00:00:00 2001 From: mar Date: Wed, 3 May 2017 13:04:59 +0000 Subject: [PATCH 2/4] feat: Support for JSX pragma comment syntax (#195) --- src/index.js | 8 ++++++ .../supports-jsx-pragma-comment/command.sh | 2 ++ .../expected/output.js | 2 ++ test/cli/supports-jsx-pragma-comment/input.js | 2 ++ test/samples/jsx.js | 26 +++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 test/cli/supports-jsx-pragma-comment/command.sh create mode 100644 test/cli/supports-jsx-pragma-comment/expected/output.js create mode 100644 test/cli/supports-jsx-pragma-comment/input.js diff --git a/src/index.js b/src/index.js index 56edecb6..445385f9 100644 --- a/src/index.js +++ b/src/index.js @@ -46,17 +46,25 @@ export function target ( target ) { export function transform ( source, options = {} ) { let ast; + let jsx = null; try { ast = parse( source, { ecmaVersion: 7, preserveParens: true, sourceType: 'module', + onComment: (block, text) => { + if ( !jsx ) { + let match = /@jsx\s+([^\s]+)/.exec( text ); + if ( match ) jsx = match[1]; + } + }, plugins: { jsx: true, objectSpread: true } }); + options.jsx = jsx || options.jsx; } catch ( err ) { err.snippet = getSnippet( source, err.loc ); err.toString = () => `${err.name}: ${err.message}\n${err.snippet}`; diff --git a/test/cli/supports-jsx-pragma-comment/command.sh b/test/cli/supports-jsx-pragma-comment/command.sh new file mode 100644 index 00000000..e254f445 --- /dev/null +++ b/test/cli/supports-jsx-pragma-comment/command.sh @@ -0,0 +1,2 @@ +# description: /* @jsx customPragma */ directives should override cli `--jsx` option (#195) +buble input.js -o actual/output.js --jsx NotReact.createElement diff --git a/test/cli/supports-jsx-pragma-comment/expected/output.js b/test/cli/supports-jsx-pragma-comment/expected/output.js new file mode 100644 index 00000000..db30e6f9 --- /dev/null +++ b/test/cli/supports-jsx-pragma-comment/expected/output.js @@ -0,0 +1,2 @@ +/* @jsx customPragma */ +var div = customPragma( 'div', null, "Hello" ) diff --git a/test/cli/supports-jsx-pragma-comment/input.js b/test/cli/supports-jsx-pragma-comment/input.js new file mode 100644 index 00000000..356d281a --- /dev/null +++ b/test/cli/supports-jsx-pragma-comment/input.js @@ -0,0 +1,2 @@ +/* @jsx customPragma */ +var div =
Hello
diff --git a/test/samples/jsx.js b/test/samples/jsx.js index 9b18a5a0..64820151 100644 --- a/test/samples/jsx.js +++ b/test/samples/jsx.js @@ -224,4 +224,30 @@ module.exports = [ ` }, + { + description: 'supports /* @jsx customPragma */ directives (#195)', + input: ` + /* @jsx customPragma */ + var div =
Hello
+ `, + output: ` + /* @jsx customPragma */ + var div = customPragma( 'div', null, "Hello" ) + ` + }, + + { + description: 'ignores subsequent /* @jsx customPragma */ directives (#195)', + input: ` + /* @jsx customPragma */ + /* @jsx customPragmaWannabe */ + var div =
Hello
+ `, + output: ` + /* @jsx customPragma */ + /* @jsx customPragmaWannabe */ + var div = customPragma( 'div', null, "Hello" ) + ` + }, + ]; From 936588c40a7314f571912102bdccd3ebbadd440a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 23 Sep 2017 16:24:48 -0400 Subject: [PATCH 3/4] fix test typo --- test/samples/jsx.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/samples/jsx.js b/test/samples/jsx.js index 5c8e22d4..6d019528 100644 --- a/test/samples/jsx.js +++ b/test/samples/jsx.js @@ -246,7 +246,8 @@ module.exports = [ output: ` /* @jsx customPragma */ /* @jsx customPragmaWannabe */ - var div = customPragma( 'div', null, "Hello" )` + var div = customPragma( 'div', null, "Hello" ) + ` }, { From b4eab5cfbf9fb8a9138ed3b06a31b2237e85a75e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 23 Sep 2017 16:31:19 -0400 Subject: [PATCH 4/4] fix test --- test/cli/supports-jsx-pragma-comment/command.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cli/supports-jsx-pragma-comment/command.sh b/test/cli/supports-jsx-pragma-comment/command.sh index e254f445..9385984e 100644 --- a/test/cli/supports-jsx-pragma-comment/command.sh +++ b/test/cli/supports-jsx-pragma-comment/command.sh @@ -1,2 +1 @@ -# description: /* @jsx customPragma */ directives should override cli `--jsx` option (#195) buble input.js -o actual/output.js --jsx NotReact.createElement