From 4988a27b6c796816e1324b08f61d9ec80fbb5c68 Mon Sep 17 00:00:00 2001 From: ArrestedDevelopment Date: Sat, 28 Mar 2015 01:41:16 -0600 Subject: [PATCH 1/2] JSX Transformer: Add 'jsxPragma' option --- src/babel/transformation/file/options.json | 7 +++++++ src/babel/transformation/transformers/other/react.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/babel/transformation/file/options.json b/src/babel/transformation/file/options.json index 06f04ef7fe..f84f766c6b 100644 --- a/src/babel/transformation/file/options.json +++ b/src/babel/transformation/file/options.json @@ -83,6 +83,13 @@ "shorthand": "L" }, + "jsxPragma": { + "type": "string", + "description": "Custom pragma to use with JSX (same functionality as @jsx comments)", + "default": "React.createElement", + "shorthand": "P" + }, + "ignore": { "type": "list" }, diff --git a/src/babel/transformation/transformers/other/react.js b/src/babel/transformation/transformers/other/react.js index 2b098e5461..a729671dd3 100644 --- a/src/babel/transformation/transformers/other/react.js +++ b/src/babel/transformation/transformers/other/react.js @@ -4,7 +4,7 @@ import * as t from "../../../types"; var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/; export function Program(node, parent, scope, file) { - var id = "React.createElement"; + var id = file.opts.jsxPragma; for (var i = 0; i < file.ast.comments.length; i++) { var comment = file.ast.comments[i]; From 121b9ca063fbd9798cc9fd831072800276f60f8b Mon Sep 17 00:00:00 2001 From: ArrestedDevelopment Date: Sat, 28 Mar 2015 02:20:01 -0600 Subject: [PATCH 2/2] Add tests for JSX Pragma option --- .../actual.js | 8 ++++++++ .../expected.js | 14 ++++++++++++++ .../options.json | 3 +++ .../react/honor-custom-jsx-pragma-option/actual.js | 6 ++++++ .../honor-custom-jsx-pragma-option/expected.js | 12 ++++++++++++ .../honor-custom-jsx-pragma-option/options.json | 3 +++ 6 files changed, 46 insertions(+) create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/actual.js create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/expected.js create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/actual.js create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/expected.js create mode 100644 test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/actual.js b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/actual.js new file mode 100644 index 0000000000..acb0d0ca1b --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/actual.js @@ -0,0 +1,8 @@ +/** @jsx dom */ + +; + +var profile =
+ +

{[user.firstName, user.lastName].join(" ")}

+
; diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/expected.js b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/expected.js new file mode 100644 index 0000000000..1febfa3188 --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/expected.js @@ -0,0 +1,14 @@ +/** @jsx dom */ + +dom(Foo, null); + +var profile = dom( + "div", + null, + dom("img", { src: "avatar.png", className: "profile" }), + dom( + "h3", + null, + [user.firstName, user.lastName].join(" ") + ) +); diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json new file mode 100644 index 0000000000..f06ff74164 --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json @@ -0,0 +1,3 @@ +{ + "jsxPragma": "foo.bar" +} diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/actual.js b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/actual.js new file mode 100644 index 0000000000..5b144eb3ee --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/actual.js @@ -0,0 +1,6 @@ +; + +var profile =
+ +

{[user.firstName, user.lastName].join(" ")}

+
; diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/expected.js b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/expected.js new file mode 100644 index 0000000000..26eb142fac --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/expected.js @@ -0,0 +1,12 @@ +dom(Foo, null); + +var profile = dom( + "div", + null, + dom("img", { src: "avatar.png", className: "profile" }), + dom( + "h3", + null, + [user.firstName, user.lastName].join(" ") + ) +); diff --git a/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json new file mode 100644 index 0000000000..223d2362fc --- /dev/null +++ b/test/core/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json @@ -0,0 +1,3 @@ +{ + "jsxPragma": "dom" +}