diff --git a/lib/ast-converter.js b/lib/ast-converter.js index 0ee75f6..066dc47 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -56,7 +56,8 @@ module.exports = (ast, extra) => { parent: null, ast, additionalOptions: { - errorOnUnknownASTType: extra.errorOnUnknownASTType || false + errorOnUnknownASTType: extra.errorOnUnknownASTType || false, + useJSXTextNode: extra.useJSXTextNode || false } }); diff --git a/lib/convert.js b/lib/convert.js index 24f16fa..f867763 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1613,16 +1613,25 @@ module.exports = function convert(config) { } + /** + * The JSX AST changed the node type for string literals + * inside a JSX Element from `Literal` to `JSXText`. We + * provide a flag to support both types until `Literal` + * node type is deprecated in ESLint v5. + */ case SyntaxKind.JsxText: { - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - value: ast.text.slice(node.pos, node.end), - raw: ast.text.slice(node.pos, node.end) - }); - const start = node.getFullStart(); const end = node.getEnd(); + const type = (additionalOptions.useJSXTextNode) + ? AST_NODE_TYPES.JSXText : AST_NODE_TYPES.Literal; + + Object.assign(result, { + type, + value: ast.text.slice(start, end), + raw: ast.text.slice(start, end) + }); + result.loc = nodeUtils.getLocFor(start, end, ast); result.range = [start, end]; diff --git a/parser.js b/parser.js index 455333f..0c38df5 100644 --- a/parser.js +++ b/parser.js @@ -48,7 +48,8 @@ function resetExtra() { tolerant: false, errors: [], strict: false, - ecmaFeatures: {} + ecmaFeatures: {}, + useJSXTextNode: false }; } @@ -104,6 +105,10 @@ function parse(code, options) { extra.errorOnUnknownASTType = true; } + if (typeof options.useJSXTextNode === "boolean" && options.useJSXTextNode) { + extra.useJSXTextNode = true; + } + } // Even if jsx option is set in typescript compiler, filename still has to diff --git a/tests/fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.result.js b/tests/fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.result.js new file mode 100644 index 0000000..50f3a52 --- /dev/null +++ b/tests/fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.result.js @@ -0,0 +1,458 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "expression": { + "type": "JSXElement", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "range": [ + 0, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "selfClosing": false, + "name": { + "type": "JSXIdentifier", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "name": "div" + }, + "attributes": [] + }, + "closingElement": { + "type": "JSXClosingElement", + "range": [ + 18, + 24 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "name": { + "type": "JSXIdentifier", + "range": [ + 20, + 23 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "name": "div" + } + }, + "children": [ + { + "type": "JSXText", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n ", + "raw": "\n " + }, + { + "type": "JSXElement", + "range": [ + 10, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "range": [ + 10, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "selfClosing": true, + "name": { + "type": "JSXIdentifier", + "range": [ + 11, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "name": "foo" + }, + "attributes": [] + }, + "closingElement": null, + "children": [] + }, + { + "type": "JSXText", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n", + "raw": "\n" + } + ] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "JSXIdentifier", + "value": "div", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "JSXText", + "value": "\n ", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "JSXIdentifier", + "value": "foo", + "range": [ + 11, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "JSXText", + "value": "\n", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "JSXIdentifier", + "value": "div", + "range": [ + 20, + 23 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + ] +}; diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.src.js b/tests/fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.src.js rename to tests/fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.src.js diff --git a/tests/fixtures/jsx-useJSXTextNode/test-content.result.js b/tests/fixtures/jsx-useJSXTextNode/test-content.result.js new file mode 100644 index 0000000..d3dc1df --- /dev/null +++ b/tests/fixtures/jsx-useJSXTextNode/test-content.result.js @@ -0,0 +1,311 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 0, + 25 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 0, + 25 + ], + "expression": { + "type": "JSXElement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 0, + 24 + ], + "openingElement": { + "type": "JSXOpeningElement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ], + "attributes": [], + "name": { + "type": "JSXIdentifier", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 1, + 4 + ], + "name": "div" + }, + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 18, + 24 + ], + "name": { + "type": "JSXIdentifier", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 20, + 23 + ], + "name": "div" + } + }, + "children": [ + { + "type": "JSXText", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 5, + 18 + ], + "value": "@test content", + "raw": "@test content" + } + ] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "JSXIdentifier", + "value": "div", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 1, + 4 + ] + }, + { + "type": "Punctuator", + "value": ">", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "JSXText", + "value": "@test content", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 5, + 18 + ] + }, + { + "type": "Punctuator", + "value": "<", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ] + }, + { + "type": "Punctuator", + "value": "/", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 19, + 20 + ] + }, + { + "type": "JSXIdentifier", + "value": "div", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 20, + 23 + ] + }, + { + "type": "Punctuator", + "value": ">", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 23, + 24 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/jsx/test-content.src.js b/tests/fixtures/jsx-useJSXTextNode/test-content.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/test-content.src.js rename to tests/fixtures/jsx-useJSXTextNode/test-content.src.js diff --git a/tests/fixtures/ecma-features/jsx/attributes.result.js b/tests/fixtures/jsx/attributes.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/attributes.result.js rename to tests/fixtures/jsx/attributes.result.js diff --git a/tests/fixtures/ecma-features/jsx/attributes.src.js b/tests/fixtures/jsx/attributes.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/attributes.src.js rename to tests/fixtures/jsx/attributes.src.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-comment.result.js b/tests/fixtures/jsx/embedded-comment.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-comment.result.js rename to tests/fixtures/jsx/embedded-comment.result.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-comment.src.js b/tests/fixtures/jsx/embedded-comment.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-comment.src.js rename to tests/fixtures/jsx/embedded-comment.src.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-conditional.result.js b/tests/fixtures/jsx/embedded-conditional.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-conditional.result.js rename to tests/fixtures/jsx/embedded-conditional.result.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-conditional.src.js b/tests/fixtures/jsx/embedded-conditional.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-conditional.src.js rename to tests/fixtures/jsx/embedded-conditional.src.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-invalid-js-identifier.result.js b/tests/fixtures/jsx/embedded-invalid-js-identifier.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-invalid-js-identifier.result.js rename to tests/fixtures/jsx/embedded-invalid-js-identifier.result.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-invalid-js-identifier.src.js b/tests/fixtures/jsx/embedded-invalid-js-identifier.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-invalid-js-identifier.src.js rename to tests/fixtures/jsx/embedded-invalid-js-identifier.src.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-tags.result.js b/tests/fixtures/jsx/embedded-tags.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-tags.result.js rename to tests/fixtures/jsx/embedded-tags.result.js diff --git a/tests/fixtures/ecma-features/jsx/embedded-tags.src.js b/tests/fixtures/jsx/embedded-tags.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/embedded-tags.src.js rename to tests/fixtures/jsx/embedded-tags.src.js diff --git a/tests/fixtures/ecma-features/jsx/empty-placeholder.result.js b/tests/fixtures/jsx/empty-placeholder.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/empty-placeholder.result.js rename to tests/fixtures/jsx/empty-placeholder.result.js diff --git a/tests/fixtures/ecma-features/jsx/empty-placeholder.src.js b/tests/fixtures/jsx/empty-placeholder.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/empty-placeholder.src.js rename to tests/fixtures/jsx/empty-placeholder.src.js diff --git a/tests/fixtures/ecma-features/jsx/escape-patterns.result.js b/tests/fixtures/jsx/escape-patterns.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/escape-patterns.result.js rename to tests/fixtures/jsx/escape-patterns.result.js diff --git a/tests/fixtures/ecma-features/jsx/escape-patterns.src.js b/tests/fixtures/jsx/escape-patterns.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/escape-patterns.src.js rename to tests/fixtures/jsx/escape-patterns.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-attribute-missing-equals.result.js b/tests/fixtures/jsx/invalid-attribute-missing-equals.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-attribute-missing-equals.result.js rename to tests/fixtures/jsx/invalid-attribute-missing-equals.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-attribute-missing-equals.src.js b/tests/fixtures/jsx/invalid-attribute-missing-equals.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-attribute-missing-equals.src.js rename to tests/fixtures/jsx/invalid-attribute-missing-equals.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-attribute.result.js b/tests/fixtures/jsx/invalid-attribute.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-attribute.result.js rename to tests/fixtures/jsx/invalid-attribute.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-attribute.src.js b/tests/fixtures/jsx/invalid-attribute.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-attribute.src.js rename to tests/fixtures/jsx/invalid-attribute.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-broken-tag.result.js b/tests/fixtures/jsx/invalid-broken-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-broken-tag.result.js rename to tests/fixtures/jsx/invalid-broken-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-broken-tag.src.js b/tests/fixtures/jsx/invalid-broken-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-broken-tag.src.js rename to tests/fixtures/jsx/invalid-broken-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-computed-end-tag-name.result.js b/tests/fixtures/jsx/invalid-computed-end-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-computed-end-tag-name.result.js rename to tests/fixtures/jsx/invalid-computed-end-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-computed-end-tag-name.src.js b/tests/fixtures/jsx/invalid-computed-end-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-computed-end-tag-name.src.js rename to tests/fixtures/jsx/invalid-computed-end-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-computed-string-end-tag-name.result.js b/tests/fixtures/jsx/invalid-computed-string-end-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-computed-string-end-tag-name.result.js rename to tests/fixtures/jsx/invalid-computed-string-end-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-computed-string-end-tag-name.src.js b/tests/fixtures/jsx/invalid-computed-string-end-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-computed-string-end-tag-name.src.js rename to tests/fixtures/jsx/invalid-computed-string-end-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-embedded-expression.result.js b/tests/fixtures/jsx/invalid-embedded-expression.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-embedded-expression.result.js rename to tests/fixtures/jsx/invalid-embedded-expression.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-embedded-expression.src.js b/tests/fixtures/jsx/invalid-embedded-expression.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-embedded-expression.src.js rename to tests/fixtures/jsx/invalid-embedded-expression.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-leading-dot-tag-name.result.js b/tests/fixtures/jsx/invalid-leading-dot-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-leading-dot-tag-name.result.js rename to tests/fixtures/jsx/invalid-leading-dot-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-leading-dot-tag-name.src.js b/tests/fixtures/jsx/invalid-leading-dot-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-leading-dot-tag-name.src.js rename to tests/fixtures/jsx/invalid-leading-dot-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-matching-placeholder-in-closing-tag.result.js b/tests/fixtures/jsx/invalid-matching-placeholder-in-closing-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-matching-placeholder-in-closing-tag.result.js rename to tests/fixtures/jsx/invalid-matching-placeholder-in-closing-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-matching-placeholder-in-closing-tag.src.js b/tests/fixtures/jsx/invalid-matching-placeholder-in-closing-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-matching-placeholder-in-closing-tag.src.js rename to tests/fixtures/jsx/invalid-matching-placeholder-in-closing-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tag.result.js b/tests/fixtures/jsx/invalid-mismatched-closing-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tag.result.js rename to tests/fixtures/jsx/invalid-mismatched-closing-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tag.src.js b/tests/fixtures/jsx/invalid-mismatched-closing-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tag.src.js rename to tests/fixtures/jsx/invalid-mismatched-closing-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tags.result.js b/tests/fixtures/jsx/invalid-mismatched-closing-tags.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tags.result.js rename to tests/fixtures/jsx/invalid-mismatched-closing-tags.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tags.src.js b/tests/fixtures/jsx/invalid-mismatched-closing-tags.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-closing-tags.src.js rename to tests/fixtures/jsx/invalid-mismatched-closing-tags.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-dot-tag-name.result.js b/tests/fixtures/jsx/invalid-mismatched-dot-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-dot-tag-name.result.js rename to tests/fixtures/jsx/invalid-mismatched-dot-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-dot-tag-name.src.js b/tests/fixtures/jsx/invalid-mismatched-dot-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-dot-tag-name.src.js rename to tests/fixtures/jsx/invalid-mismatched-dot-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-namespace-tag.result.js b/tests/fixtures/jsx/invalid-mismatched-namespace-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-namespace-tag.result.js rename to tests/fixtures/jsx/invalid-mismatched-namespace-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-mismatched-namespace-tag.src.js b/tests/fixtures/jsx/invalid-mismatched-namespace-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-mismatched-namespace-tag.src.js rename to tests/fixtures/jsx/invalid-mismatched-namespace-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag-attribute-placeholder.result.js b/tests/fixtures/jsx/invalid-missing-closing-tag-attribute-placeholder.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag-attribute-placeholder.result.js rename to tests/fixtures/jsx/invalid-missing-closing-tag-attribute-placeholder.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag-attribute-placeholder.src.js b/tests/fixtures/jsx/invalid-missing-closing-tag-attribute-placeholder.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag-attribute-placeholder.src.js rename to tests/fixtures/jsx/invalid-missing-closing-tag-attribute-placeholder.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag.result.js b/tests/fixtures/jsx/invalid-missing-closing-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag.result.js rename to tests/fixtures/jsx/invalid-missing-closing-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag.src.js b/tests/fixtures/jsx/invalid-missing-closing-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-closing-tag.src.js rename to tests/fixtures/jsx/invalid-missing-closing-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-namespace-name.result.js b/tests/fixtures/jsx/invalid-missing-namespace-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-namespace-name.result.js rename to tests/fixtures/jsx/invalid-missing-namespace-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-namespace-name.src.js b/tests/fixtures/jsx/invalid-missing-namespace-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-namespace-name.src.js rename to tests/fixtures/jsx/invalid-missing-namespace-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-namespace-value.result.js b/tests/fixtures/jsx/invalid-missing-namespace-value.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-namespace-value.result.js rename to tests/fixtures/jsx/invalid-missing-namespace-value.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-namespace-value.src.js b/tests/fixtures/jsx/invalid-missing-namespace-value.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-namespace-value.src.js rename to tests/fixtures/jsx/invalid-missing-namespace-value.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-spread-operator.result.js b/tests/fixtures/jsx/invalid-missing-spread-operator.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-spread-operator.result.js rename to tests/fixtures/jsx/invalid-missing-spread-operator.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-missing-spread-operator.src.js b/tests/fixtures/jsx/invalid-missing-spread-operator.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-missing-spread-operator.src.js rename to tests/fixtures/jsx/invalid-missing-spread-operator.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-namespace-name-with-docts.result.js b/tests/fixtures/jsx/invalid-namespace-name-with-docts.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-namespace-name-with-docts.result.js rename to tests/fixtures/jsx/invalid-namespace-name-with-docts.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-namespace-name-with-docts.src.js b/tests/fixtures/jsx/invalid-namespace-name-with-docts.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-namespace-name-with-docts.src.js rename to tests/fixtures/jsx/invalid-namespace-name-with-docts.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-namespace-value-with-dots.result.js b/tests/fixtures/jsx/invalid-namespace-value-with-dots.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-namespace-value-with-dots.result.js rename to tests/fixtures/jsx/invalid-namespace-value-with-dots.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-namespace-value-with-dots.src.js b/tests/fixtures/jsx/invalid-namespace-value-with-dots.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-namespace-value-with-dots.src.js rename to tests/fixtures/jsx/invalid-namespace-value-with-dots.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-common-parent-with-comment.result.js b/tests/fixtures/jsx/invalid-no-common-parent-with-comment.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-common-parent-with-comment.result.js rename to tests/fixtures/jsx/invalid-no-common-parent-with-comment.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-common-parent-with-comment.src.js b/tests/fixtures/jsx/invalid-no-common-parent-with-comment.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-common-parent-with-comment.src.js rename to tests/fixtures/jsx/invalid-no-common-parent-with-comment.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-common-parent.result.js b/tests/fixtures/jsx/invalid-no-common-parent.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-common-parent.result.js rename to tests/fixtures/jsx/invalid-no-common-parent.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-common-parent.src.js b/tests/fixtures/jsx/invalid-no-common-parent.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-common-parent.src.js rename to tests/fixtures/jsx/invalid-no-common-parent.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-tag-name.result.js b/tests/fixtures/jsx/invalid-no-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-tag-name.result.js rename to tests/fixtures/jsx/invalid-no-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-no-tag-name.src.js b/tests/fixtures/jsx/invalid-no-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-no-tag-name.src.js rename to tests/fixtures/jsx/invalid-no-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-placeholder-in-closing-tag.result.js b/tests/fixtures/jsx/invalid-placeholder-in-closing-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-placeholder-in-closing-tag.result.js rename to tests/fixtures/jsx/invalid-placeholder-in-closing-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-placeholder-in-closing-tag.src.js b/tests/fixtures/jsx/invalid-placeholder-in-closing-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-placeholder-in-closing-tag.src.js rename to tests/fixtures/jsx/invalid-placeholder-in-closing-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-trailing-dot-tag-name.result.js b/tests/fixtures/jsx/invalid-trailing-dot-tag-name.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-trailing-dot-tag-name.result.js rename to tests/fixtures/jsx/invalid-trailing-dot-tag-name.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-trailing-dot-tag-name.src.js b/tests/fixtures/jsx/invalid-trailing-dot-tag-name.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-trailing-dot-tag-name.src.js rename to tests/fixtures/jsx/invalid-trailing-dot-tag-name.src.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-unexpected-comma.result.js b/tests/fixtures/jsx/invalid-unexpected-comma.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-unexpected-comma.result.js rename to tests/fixtures/jsx/invalid-unexpected-comma.result.js diff --git a/tests/fixtures/ecma-features/jsx/invalid-unexpected-comma.src.js b/tests/fixtures/jsx/invalid-unexpected-comma.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/invalid-unexpected-comma.src.js rename to tests/fixtures/jsx/invalid-unexpected-comma.src.js diff --git a/tests/fixtures/ecma-features/jsx/japanese-characters.result.js b/tests/fixtures/jsx/japanese-characters.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/japanese-characters.result.js rename to tests/fixtures/jsx/japanese-characters.result.js diff --git a/tests/fixtures/ecma-features/jsx/japanese-characters.src.js b/tests/fixtures/jsx/japanese-characters.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/japanese-characters.src.js rename to tests/fixtures/jsx/japanese-characters.src.js diff --git a/tests/fixtures/ecma-features/jsx/less-than-operator.result.js b/tests/fixtures/jsx/less-than-operator.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/less-than-operator.result.js rename to tests/fixtures/jsx/less-than-operator.result.js diff --git a/tests/fixtures/ecma-features/jsx/less-than-operator.src.js b/tests/fixtures/jsx/less-than-operator.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/less-than-operator.src.js rename to tests/fixtures/jsx/less-than-operator.src.js diff --git a/tests/fixtures/ecma-features/jsx/multiple-blank-spaces.result.js b/tests/fixtures/jsx/multiple-blank-spaces.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/multiple-blank-spaces.result.js rename to tests/fixtures/jsx/multiple-blank-spaces.result.js diff --git a/tests/fixtures/ecma-features/jsx/multiple-blank-spaces.src.js b/tests/fixtures/jsx/multiple-blank-spaces.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/multiple-blank-spaces.src.js rename to tests/fixtures/jsx/multiple-blank-spaces.src.js diff --git a/tests/fixtures/ecma-features/jsx/namespaced-attribute-and-value-inserted.result.js b/tests/fixtures/jsx/namespaced-attribute-and-value-inserted.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/namespaced-attribute-and-value-inserted.result.js rename to tests/fixtures/jsx/namespaced-attribute-and-value-inserted.result.js diff --git a/tests/fixtures/ecma-features/jsx/namespaced-attribute-and-value-inserted.src.js b/tests/fixtures/jsx/namespaced-attribute-and-value-inserted.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/namespaced-attribute-and-value-inserted.src.js rename to tests/fixtures/jsx/namespaced-attribute-and-value-inserted.src.js diff --git a/tests/fixtures/ecma-features/jsx/namespaced-name-and-attribute.result.js b/tests/fixtures/jsx/namespaced-name-and-attribute.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/namespaced-name-and-attribute.result.js rename to tests/fixtures/jsx/namespaced-name-and-attribute.result.js diff --git a/tests/fixtures/ecma-features/jsx/namespaced-name-and-attribute.src.js b/tests/fixtures/jsx/namespaced-name-and-attribute.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/namespaced-name-and-attribute.src.js rename to tests/fixtures/jsx/namespaced-name-and-attribute.src.js diff --git a/tests/fixtures/ecma-features/jsx/newslines-and-entities.result.js b/tests/fixtures/jsx/newslines-and-entities.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/newslines-and-entities.result.js rename to tests/fixtures/jsx/newslines-and-entities.result.js diff --git a/tests/fixtures/ecma-features/jsx/newslines-and-entities.src.js b/tests/fixtures/jsx/newslines-and-entities.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/newslines-and-entities.src.js rename to tests/fixtures/jsx/newslines-and-entities.src.js diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js b/tests/fixtures/jsx/self-closing-tag-inside-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag-inside-tag.result.js rename to tests/fixtures/jsx/self-closing-tag-inside-tag.result.js diff --git a/tests/fixtures/jsx/self-closing-tag-inside-tag.src.js b/tests/fixtures/jsx/self-closing-tag-inside-tag.src.js new file mode 100644 index 0000000..b1b2540 --- /dev/null +++ b/tests/fixtures/jsx/self-closing-tag-inside-tag.src.js @@ -0,0 +1,3 @@ +
+ +
diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag-with-newline.result.js b/tests/fixtures/jsx/self-closing-tag-with-newline.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag-with-newline.result.js rename to tests/fixtures/jsx/self-closing-tag-with-newline.result.js diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag-with-newline.src.js b/tests/fixtures/jsx/self-closing-tag-with-newline.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag-with-newline.src.js rename to tests/fixtures/jsx/self-closing-tag-with-newline.src.js diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag.result.js b/tests/fixtures/jsx/self-closing-tag.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag.result.js rename to tests/fixtures/jsx/self-closing-tag.result.js diff --git a/tests/fixtures/ecma-features/jsx/self-closing-tag.src.js b/tests/fixtures/jsx/self-closing-tag.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/self-closing-tag.src.js rename to tests/fixtures/jsx/self-closing-tag.src.js diff --git a/tests/fixtures/ecma-features/jsx/spread-operator-attribute-and-regular-attribute.result.js b/tests/fixtures/jsx/spread-operator-attribute-and-regular-attribute.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/spread-operator-attribute-and-regular-attribute.result.js rename to tests/fixtures/jsx/spread-operator-attribute-and-regular-attribute.result.js diff --git a/tests/fixtures/ecma-features/jsx/spread-operator-attribute-and-regular-attribute.src.js b/tests/fixtures/jsx/spread-operator-attribute-and-regular-attribute.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/spread-operator-attribute-and-regular-attribute.src.js rename to tests/fixtures/jsx/spread-operator-attribute-and-regular-attribute.src.js diff --git a/tests/fixtures/ecma-features/jsx/spread-operator-attributes.result.js b/tests/fixtures/jsx/spread-operator-attributes.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/spread-operator-attributes.result.js rename to tests/fixtures/jsx/spread-operator-attributes.result.js diff --git a/tests/fixtures/ecma-features/jsx/spread-operator-attributes.src.js b/tests/fixtures/jsx/spread-operator-attributes.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/spread-operator-attributes.src.js rename to tests/fixtures/jsx/spread-operator-attributes.src.js diff --git a/tests/fixtures/ecma-features/jsx/tag-names-with-dots.result.js b/tests/fixtures/jsx/tag-names-with-dots.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/tag-names-with-dots.result.js rename to tests/fixtures/jsx/tag-names-with-dots.result.js diff --git a/tests/fixtures/ecma-features/jsx/tag-names-with-dots.src.js b/tests/fixtures/jsx/tag-names-with-dots.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/tag-names-with-dots.src.js rename to tests/fixtures/jsx/tag-names-with-dots.src.js diff --git a/tests/fixtures/ecma-features/jsx/tag-names-with-multi-dots.result.js b/tests/fixtures/jsx/tag-names-with-multi-dots.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/tag-names-with-multi-dots.result.js rename to tests/fixtures/jsx/tag-names-with-multi-dots.result.js diff --git a/tests/fixtures/ecma-features/jsx/tag-names-with-multi-dots.src.js b/tests/fixtures/jsx/tag-names-with-multi-dots.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/tag-names-with-multi-dots.src.js rename to tests/fixtures/jsx/tag-names-with-multi-dots.src.js diff --git a/tests/fixtures/ecma-features/jsx/test-content.result.js b/tests/fixtures/jsx/test-content.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/test-content.result.js rename to tests/fixtures/jsx/test-content.result.js diff --git a/tests/fixtures/jsx/test-content.src.js b/tests/fixtures/jsx/test-content.src.js new file mode 100644 index 0000000..ffaed57 --- /dev/null +++ b/tests/fixtures/jsx/test-content.src.js @@ -0,0 +1 @@ +
@test content
; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/jsx/trailing-spread-operator-attribute.result.js b/tests/fixtures/jsx/trailing-spread-operator-attribute.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/trailing-spread-operator-attribute.result.js rename to tests/fixtures/jsx/trailing-spread-operator-attribute.result.js diff --git a/tests/fixtures/ecma-features/jsx/trailing-spread-operator-attribute.src.js b/tests/fixtures/jsx/trailing-spread-operator-attribute.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/trailing-spread-operator-attribute.src.js rename to tests/fixtures/jsx/trailing-spread-operator-attribute.src.js diff --git a/tests/fixtures/ecma-features/jsx/unknown-escape-pattern.result.js b/tests/fixtures/jsx/unknown-escape-pattern.result.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/unknown-escape-pattern.result.js rename to tests/fixtures/jsx/unknown-escape-pattern.result.js diff --git a/tests/fixtures/ecma-features/jsx/unknown-escape-pattern.src.js b/tests/fixtures/jsx/unknown-escape-pattern.src.js similarity index 100% rename from tests/fixtures/ecma-features/jsx/unknown-escape-pattern.src.js rename to tests/fixtures/jsx/unknown-escape-pattern.src.js diff --git a/tests/lib/ecma-features.js b/tests/lib/ecma-features.js index 8813690..b698ac9 100644 --- a/tests/lib/ecma-features.js +++ b/tests/lib/ecma-features.js @@ -26,15 +26,8 @@ const FIXTURES_DIR = "./tests/fixtures/ecma-features"; // var FIXTURES_MIX_DIR = "./tests/fixtures/ecma-features-mix"; -const filesWithOutsandingTSIssues = [ - "jsx/embedded-tags", // https://github.com/Microsoft/TypeScript/issues/7410 - "jsx/namespaced-attribute-and-value-inserted", // https://github.com/Microsoft/TypeScript/issues/7411 - "jsx/namespaced-name-and-attribute" // https://github.com/Microsoft/TypeScript/issues/7411 -]; - const testFiles = shelljs.find(FIXTURES_DIR) .filter(filename => filename.indexOf(".src.js") > -1) - .filter(filename => filesWithOutsandingTSIssues.every(fileName => filename.indexOf(fileName) === -1)) // strip off ".src.js" .map(filename => filename.substring(FIXTURES_DIR.length - 1, filename.length - 7)) .filter(filename => !(/error-|invalid-|globalReturn/.test(filename))); diff --git a/tests/lib/jsx.js b/tests/lib/jsx.js new file mode 100644 index 0000000..38f615e --- /dev/null +++ b/tests/lib/jsx.js @@ -0,0 +1,109 @@ +/** + * @fileoverview Tests for ECMA feature flags + * @author Nicholas C. Zakas + * @copyright jQuery Foundation and other contributors, https://jquery.org/ + * MIT License + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const assert = require("chai").assert, + leche = require("leche"), + path = require("path"), + parser = require("../../parser"), + shelljs = require("shelljs"), + tester = require("./tester"); + +//------------------------------------------------------------------------------ +// Setup +//------------------------------------------------------------------------------ + +const JSX_FIXTURES_DIR = "./tests/fixtures/jsx"; + +const filesWithOutsandingTSIssues = [ + "jsx/embedded-tags", // https://github.com/Microsoft/TypeScript/issues/7410 + "jsx/namespaced-attribute-and-value-inserted", // https://github.com/Microsoft/TypeScript/issues/7411 + "jsx/namespaced-name-and-attribute", // https://github.com/Microsoft/TypeScript/issues/7411 + "jsx/invalid-namespace-value-with-dots" // https://github.com/Microsoft/TypeScript/issues/7411 +]; + +const jsxTestFiles = shelljs.find(JSX_FIXTURES_DIR) + .filter(filename => filename.indexOf(".src.js") > -1) + .filter(filename => filesWithOutsandingTSIssues.every(fileName => filename.indexOf(fileName) === -1)) + // strip off ".src.js" + .map(filename => filename.substring(JSX_FIXTURES_DIR.length - 1, filename.length - 7)); + +const JSX_JSXTEXT_FIXTURES_DIR = "./tests/fixtures/jsx-useJSXTextNode"; + +const jsxTextTestFiles = shelljs.find(JSX_JSXTEXT_FIXTURES_DIR) + .filter(filename => filename.indexOf(".src.js") > -1) + // strip off ".src.js" + .map(filename => filename.substring(JSX_JSXTEXT_FIXTURES_DIR.length - 1, filename.length - 7)); + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +describe("JSX", () => { + + let config; + + beforeEach(() => { + config = { + loc: true, + range: true, + tokens: true, + errorOnUnknownASTType: true, + ecmaFeatures: { + jsx: true + } + }; + }); + + /** + * Test each fixture file + * @param {string} fixturesDir Fixtures Directory + * @param {boolean} useJSXTextNode Use JSX Text Node + * @returns {void} + */ + function testFixture(fixturesDir, useJSXTextNode) { + + return filename => { + // Uncomment and fill in filename to focus on a single file + // var filename = "jsx/invalid-matching-placeholder-in-closing-tag"; + const code = shelljs.cat(`${path.resolve(fixturesDir, filename)}.src.js`); + + it(`should parse correctly when ${filename} is true`, () => { + config.useJSXTextNode = useJSXTextNode; + const expected = require(`${path.resolve(__dirname, "../../", fixturesDir, filename)}.result.js`); + let result; + + try { + result = parser.parse(code, config); + result = tester.getRaw(result); + } catch (ex) { + + // format of error isn't exactly the same, just check if it's expected + if (expected.message) { + return; + } + throw ex; + + + } + assert.deepEqual(result, expected); + }); + }; + } + + describe("useJSXTextNode: false", () => { + leche.withData(jsxTestFiles, testFixture(JSX_FIXTURES_DIR, false)); + }); + describe("useJSXTextNode: true", () => { + leche.withData(jsxTextTestFiles, testFixture(JSX_JSXTEXT_FIXTURES_DIR, true)); + }); +});