diff --git a/README.md b/README.md index 28693ce3..7309d23b 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,9 @@ var ast = espree.parse(code, { // enable parsing classes classes: true, + // enable parsing of modules + modules: true, + // enable React JSX parsing jsx: true, diff --git a/espree.js b/espree.js index ff0fcb8a..8b87f9af 100644 --- a/espree.js +++ b/espree.js @@ -4776,8 +4776,7 @@ function parseExportNamedDeclaration() { case "let": case "const": case "var": - // TODO: enable this case when Class gets implemented - // case "class": + case "class": case "function": declaration = parseSourceElement(); return markerApply(marker, astNodeFactory.createExportNamedDeclaration(declaration, specifiers, null)); @@ -4825,8 +4824,8 @@ function parseExportDefaultDeclaration() { // export default ... expectKeyword("export"); expectKeyword("default"); - // TODO: or matchKeyword("class") after implementing classes - if (matchKeyword("function")) { + + if (matchKeyword("function") || matchKeyword("class")) { possibleIdentifierToken = lookahead2(); if (isIdentifierName(possibleIdentifierToken)) { // covers: @@ -4842,13 +4841,11 @@ function parseExportDefaultDeclaration() { // TODO: change this to declaration once we get FunctionDeclaration with nullable name declaration = parseFunctionExpression(); return markerApply(marker, astNodeFactory.createExportDefaultDeclaration(declaration)); + } else if (lookahead.value === "class") { + // TODO: change this to declaration once we get ClassDeclaration with nullable name + parseClassExpression(); + return markerApply(marker, astNodeFactory.createExportDefaultDeclaration(declaration)); } - // TODO: enable after implementing classes - // else if (lookahead.value === "class") { - // // TODO: change this to declaration once we get ClassDeclaration with nullable name - // parseClassExpression() - // return markerApply(marker, astNodeFactory.createExportDefaultDeclaration(declaration)); - // } } if (matchContextualKeyword("from")) { @@ -5127,17 +5124,19 @@ function parseClassDeclaration() { function parseSourceElement() { - var allowClasses = extra.ecmaFeatures.classes; + var allowClasses = extra.ecmaFeatures.classes, + allowModules = extra.ecmaFeatures.modules, + allowBlockBindings = extra.ecmaFeatures.blockBindings; if (lookahead.type === Token.Keyword) { switch (lookahead.value) { case "export": - if (!extra.isModule) { + if (!allowModules) { throwErrorTolerant({}, Messages.IllegalExportDeclaration); } return parseExportDeclaration(); case "import": - if (!extra.isModule) { + if (!allowModules) { throwErrorTolerant({}, Messages.IllegalImportDeclaration); } return parseImportDeclaration(); @@ -5150,7 +5149,7 @@ function parseSourceElement() { break; case "const": case "let": - if (extra.ecmaFeatures.blockBindings) { + if (allowBlockBindings) { return parseConstLetDeclaration(lookahead.value); } /* falls through */ @@ -5210,7 +5209,7 @@ function parseProgram() { skipComment(); peek(); marker = markerCreate(); - strict = extra.isModule; + strict = extra.ecmaFeatures.modules; body = parseSourceElements(); return markerApply(marker, astNodeFactory.createProgram(body)); @@ -5393,11 +5392,6 @@ function parse(code, options) { extra.loc = (typeof options.loc === "boolean") && options.loc; extra.attachComment = (typeof options.attachComment === "boolean") && options.attachComment; - // apply parsing flags - if (options.ecmaFeatures && typeof options.ecmaFeatures === "object") { - extra.ecmaFeatures = options.ecmaFeatures; - } - if (extra.loc && options.source !== null && options.source !== undefined) { extra.source = toString(options.source); } @@ -5418,8 +5412,8 @@ function parse(code, options) { extra.trailingComments = []; extra.leadingComments = []; } + if (options.sourceType === "module") { - // TODO: enable all other ES6 features that are supported in modules extra.ecmaFeatures.blockBindings = true; extra.ecmaFeatures.regexUFlag = true; extra.ecmaFeatures.regexYFlag = true; @@ -5434,9 +5428,16 @@ function parse(code, options) { extra.ecmaFeatures.objectLiteralShorthandProperties = true; extra.ecmaFeatures.objectLiteralDuplicateProperties = true; extra.ecmaFeatures.generators = true; - extra.isModule = true; - // TODO: enable classes when it becomes available + extra.ecmaFeatures.destructuring = true; + extra.ecmaFeatures.classes = true; + extra.ecmaFeatures.modules = true; } + + // apply parsing flags after sourceType to allow overriding + if (options.ecmaFeatures && typeof options.ecmaFeatures === "object") { + extra.ecmaFeatures = options.ecmaFeatures; + } + } try { diff --git a/lib/features.js b/lib/features.js index cc0be826..c33274a4 100644 --- a/lib/features.js +++ b/lib/features.js @@ -100,6 +100,9 @@ module.exports = { // enable parsing of classes classes: false, + // enable parsing of modules + modules: false, + // React JSX parsing jsx: false, diff --git a/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.config.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.config.js new file mode 100644 index 00000000..4e67c799 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.config.js @@ -0,0 +1,4 @@ +module.exports = { + blockBindings: true, + modules: true +}; diff --git a/tests/fixtures/modules/export/export-const-number.result.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.result.js similarity index 100% rename from tests/fixtures/modules/export/export-const-number.result.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.result.js diff --git a/tests/fixtures/modules/export/export-const-number.src.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.src.js similarity index 100% rename from tests/fixtures/modules/export/export-const-number.src.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-number.src.js diff --git a/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.config.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.config.js new file mode 100644 index 00000000..4e67c799 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.config.js @@ -0,0 +1,4 @@ +module.exports = { + blockBindings: true, + modules: true +}; diff --git a/tests/fixtures/modules/export/export-const-object.result.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.result.js similarity index 100% rename from tests/fixtures/modules/export/export-const-object.result.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.result.js diff --git a/tests/fixtures/modules/export/export-const-object.src.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.src.js similarity index 100% rename from tests/fixtures/modules/export/export-const-object.src.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-const-object.src.js diff --git a/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.config.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.config.js new file mode 100644 index 00000000..4e67c799 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.config.js @@ -0,0 +1,4 @@ +module.exports = { + blockBindings: true, + modules: true +}; diff --git a/tests/fixtures/modules/export/export-let-number.result.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.result.js similarity index 100% rename from tests/fixtures/modules/export/export-let-number.result.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.result.js diff --git a/tests/fixtures/modules/export/export-let-number.src.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.src.js similarity index 100% rename from tests/fixtures/modules/export/export-let-number.src.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-number.src.js diff --git a/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.config.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.config.js new file mode 100644 index 00000000..4e67c799 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.config.js @@ -0,0 +1,4 @@ +module.exports = { + blockBindings: true, + modules: true +}; diff --git a/tests/fixtures/modules/export/export-let-object.result.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.result.js similarity index 100% rename from tests/fixtures/modules/export/export-let-object.result.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.result.js diff --git a/tests/fixtures/modules/export/export-let-object.src.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.src.js similarity index 100% rename from tests/fixtures/modules/export/export-let-object.src.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let-object.src.js diff --git a/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.config.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.config.js new file mode 100644 index 00000000..4e67c799 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.config.js @@ -0,0 +1,4 @@ +module.exports = { + blockBindings: true, + modules: true +}; diff --git a/tests/fixtures/modules/export/export-let.result.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.result.js similarity index 100% rename from tests/fixtures/modules/export/export-let.result.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.result.js diff --git a/tests/fixtures/modules/export/export-let.src.js b/tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.src.js similarity index 100% rename from tests/fixtures/modules/export/export-let.src.js rename to tests/fixtures/ecma-features-mix/modules-and-blockBindings/export-let.src.js diff --git a/tests/fixtures/modules/export/export-default-array.result.js b/tests/fixtures/ecma-features/modules/export-default-array.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-array.result.js rename to tests/fixtures/ecma-features/modules/export-default-array.result.js diff --git a/tests/fixtures/modules/export/export-default-array.src.js b/tests/fixtures/ecma-features/modules/export-default-array.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-array.src.js rename to tests/fixtures/ecma-features/modules/export-default-array.src.js diff --git a/tests/fixtures/modules/export/export-default-expression.result.js b/tests/fixtures/ecma-features/modules/export-default-expression.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-expression.result.js rename to tests/fixtures/ecma-features/modules/export-default-expression.result.js diff --git a/tests/fixtures/modules/export/export-default-expression.src.js b/tests/fixtures/ecma-features/modules/export-default-expression.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-expression.src.js rename to tests/fixtures/ecma-features/modules/export-default-expression.src.js diff --git a/tests/fixtures/modules/export/export-default-function.result.js b/tests/fixtures/ecma-features/modules/export-default-function.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-function.result.js rename to tests/fixtures/ecma-features/modules/export-default-function.result.js diff --git a/tests/fixtures/modules/export/export-default-function.src.js b/tests/fixtures/ecma-features/modules/export-default-function.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-function.src.js rename to tests/fixtures/ecma-features/modules/export-default-function.src.js diff --git a/tests/fixtures/modules/export/export-default-named-function.result.js b/tests/fixtures/ecma-features/modules/export-default-named-function.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-named-function.result.js rename to tests/fixtures/ecma-features/modules/export-default-named-function.result.js diff --git a/tests/fixtures/modules/export/export-default-named-function.src.js b/tests/fixtures/ecma-features/modules/export-default-named-function.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-named-function.src.js rename to tests/fixtures/ecma-features/modules/export-default-named-function.src.js diff --git a/tests/fixtures/modules/export/export-default-number.result.js b/tests/fixtures/ecma-features/modules/export-default-number.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-number.result.js rename to tests/fixtures/ecma-features/modules/export-default-number.result.js diff --git a/tests/fixtures/modules/export/export-default-number.src.js b/tests/fixtures/ecma-features/modules/export-default-number.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-number.src.js rename to tests/fixtures/ecma-features/modules/export-default-number.src.js diff --git a/tests/fixtures/modules/export/export-default-object.result.js b/tests/fixtures/ecma-features/modules/export-default-object.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-object.result.js rename to tests/fixtures/ecma-features/modules/export-default-object.result.js diff --git a/tests/fixtures/modules/export/export-default-object.src.js b/tests/fixtures/ecma-features/modules/export-default-object.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-object.src.js rename to tests/fixtures/ecma-features/modules/export-default-object.src.js diff --git a/tests/fixtures/modules/export/export-default-value.result.js b/tests/fixtures/ecma-features/modules/export-default-value.result.js similarity index 100% rename from tests/fixtures/modules/export/export-default-value.result.js rename to tests/fixtures/ecma-features/modules/export-default-value.result.js diff --git a/tests/fixtures/modules/export/export-default-value.src.js b/tests/fixtures/ecma-features/modules/export-default-value.src.js similarity index 100% rename from tests/fixtures/modules/export/export-default-value.src.js rename to tests/fixtures/ecma-features/modules/export-default-value.src.js diff --git a/tests/fixtures/modules/export/export-from-batch.result.js b/tests/fixtures/ecma-features/modules/export-from-batch.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-batch.result.js rename to tests/fixtures/ecma-features/modules/export-from-batch.result.js diff --git a/tests/fixtures/modules/export/export-from-batch.src.js b/tests/fixtures/ecma-features/modules/export-from-batch.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-batch.src.js rename to tests/fixtures/ecma-features/modules/export-from-batch.src.js diff --git a/tests/fixtures/modules/export/export-from-default.result.js b/tests/fixtures/ecma-features/modules/export-from-default.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-default.result.js rename to tests/fixtures/ecma-features/modules/export-from-default.result.js diff --git a/tests/fixtures/modules/export/export-from-default.src.js b/tests/fixtures/ecma-features/modules/export-from-default.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-default.src.js rename to tests/fixtures/ecma-features/modules/export-from-default.src.js diff --git a/tests/fixtures/modules/export/export-from-named-as-default.result.js b/tests/fixtures/ecma-features/modules/export-from-named-as-default.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-default.result.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-default.result.js diff --git a/tests/fixtures/modules/export/export-from-named-as-default.src.js b/tests/fixtures/ecma-features/modules/export-from-named-as-default.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-default.src.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-default.src.js diff --git a/tests/fixtures/modules/export/export-from-named-as-specifier.result.js b/tests/fixtures/ecma-features/modules/export-from-named-as-specifier.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-specifier.result.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-specifier.result.js diff --git a/tests/fixtures/modules/export/export-from-named-as-specifier.src.js b/tests/fixtures/ecma-features/modules/export-from-named-as-specifier.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-specifier.src.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-specifier.src.js diff --git a/tests/fixtures/modules/export/export-from-named-as-specifiers.result.js b/tests/fixtures/ecma-features/modules/export-from-named-as-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-specifiers.result.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-specifiers.result.js diff --git a/tests/fixtures/modules/export/export-from-named-as-specifiers.src.js b/tests/fixtures/ecma-features/modules/export-from-named-as-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-named-as-specifiers.src.js rename to tests/fixtures/ecma-features/modules/export-from-named-as-specifiers.src.js diff --git a/tests/fixtures/modules/export/export-from-specifier.result.js b/tests/fixtures/ecma-features/modules/export-from-specifier.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-specifier.result.js rename to tests/fixtures/ecma-features/modules/export-from-specifier.result.js diff --git a/tests/fixtures/modules/export/export-from-specifier.src.js b/tests/fixtures/ecma-features/modules/export-from-specifier.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-specifier.src.js rename to tests/fixtures/ecma-features/modules/export-from-specifier.src.js diff --git a/tests/fixtures/modules/export/export-from-specifiers.result.js b/tests/fixtures/ecma-features/modules/export-from-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/export/export-from-specifiers.result.js rename to tests/fixtures/ecma-features/modules/export-from-specifiers.result.js diff --git a/tests/fixtures/modules/export/export-from-specifiers.src.js b/tests/fixtures/ecma-features/modules/export-from-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/export/export-from-specifiers.src.js rename to tests/fixtures/ecma-features/modules/export-from-specifiers.src.js diff --git a/tests/fixtures/modules/export/export-function.result.js b/tests/fixtures/ecma-features/modules/export-function.result.js similarity index 100% rename from tests/fixtures/modules/export/export-function.result.js rename to tests/fixtures/ecma-features/modules/export-function.result.js diff --git a/tests/fixtures/modules/export/export-function.src.js b/tests/fixtures/ecma-features/modules/export-function.src.js similarity index 100% rename from tests/fixtures/modules/export/export-function.src.js rename to tests/fixtures/ecma-features/modules/export-function.src.js diff --git a/tests/fixtures/modules/export/export-named-as-default.result.js b/tests/fixtures/ecma-features/modules/export-named-as-default.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-default.result.js rename to tests/fixtures/ecma-features/modules/export-named-as-default.result.js diff --git a/tests/fixtures/modules/export/export-named-as-default.src.js b/tests/fixtures/ecma-features/modules/export-named-as-default.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-default.src.js rename to tests/fixtures/ecma-features/modules/export-named-as-default.src.js diff --git a/tests/fixtures/modules/export/export-named-as-specifier.result.js b/tests/fixtures/ecma-features/modules/export-named-as-specifier.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-specifier.result.js rename to tests/fixtures/ecma-features/modules/export-named-as-specifier.result.js diff --git a/tests/fixtures/modules/export/export-named-as-specifier.src.js b/tests/fixtures/ecma-features/modules/export-named-as-specifier.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-specifier.src.js rename to tests/fixtures/ecma-features/modules/export-named-as-specifier.src.js diff --git a/tests/fixtures/modules/export/export-named-as-specifiers.result.js b/tests/fixtures/ecma-features/modules/export-named-as-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-specifiers.result.js rename to tests/fixtures/ecma-features/modules/export-named-as-specifiers.result.js diff --git a/tests/fixtures/modules/export/export-named-as-specifiers.src.js b/tests/fixtures/ecma-features/modules/export-named-as-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-as-specifiers.src.js rename to tests/fixtures/ecma-features/modules/export-named-as-specifiers.src.js diff --git a/tests/fixtures/modules/export/export-named-empty.result.js b/tests/fixtures/ecma-features/modules/export-named-empty.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-empty.result.js rename to tests/fixtures/ecma-features/modules/export-named-empty.result.js diff --git a/tests/fixtures/modules/export/export-named-empty.src.js b/tests/fixtures/ecma-features/modules/export-named-empty.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-empty.src.js rename to tests/fixtures/ecma-features/modules/export-named-empty.src.js diff --git a/tests/fixtures/modules/export/export-named-specifier.result.js b/tests/fixtures/ecma-features/modules/export-named-specifier.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-specifier.result.js rename to tests/fixtures/ecma-features/modules/export-named-specifier.result.js diff --git a/tests/fixtures/modules/export/export-named-specifier.src.js b/tests/fixtures/ecma-features/modules/export-named-specifier.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-specifier.src.js rename to tests/fixtures/ecma-features/modules/export-named-specifier.src.js diff --git a/tests/fixtures/modules/export/export-named-specifiers.result.js b/tests/fixtures/ecma-features/modules/export-named-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/export/export-named-specifiers.result.js rename to tests/fixtures/ecma-features/modules/export-named-specifiers.result.js diff --git a/tests/fixtures/modules/export/export-named-specifiers.src.js b/tests/fixtures/ecma-features/modules/export-named-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/export/export-named-specifiers.src.js rename to tests/fixtures/ecma-features/modules/export-named-specifiers.src.js diff --git a/tests/fixtures/modules/export/export-var-anonymous-function.result.js b/tests/fixtures/ecma-features/modules/export-var-anonymous-function.result.js similarity index 100% rename from tests/fixtures/modules/export/export-var-anonymous-function.result.js rename to tests/fixtures/ecma-features/modules/export-var-anonymous-function.result.js diff --git a/tests/fixtures/modules/export/export-var-anonymous-function.src.js b/tests/fixtures/ecma-features/modules/export-var-anonymous-function.src.js similarity index 100% rename from tests/fixtures/modules/export/export-var-anonymous-function.src.js rename to tests/fixtures/ecma-features/modules/export-var-anonymous-function.src.js diff --git a/tests/fixtures/modules/export/export-var-number.result.js b/tests/fixtures/ecma-features/modules/export-var-number.result.js similarity index 100% rename from tests/fixtures/modules/export/export-var-number.result.js rename to tests/fixtures/ecma-features/modules/export-var-number.result.js diff --git a/tests/fixtures/modules/export/export-var-number.src.js b/tests/fixtures/ecma-features/modules/export-var-number.src.js similarity index 100% rename from tests/fixtures/modules/export/export-var-number.src.js rename to tests/fixtures/ecma-features/modules/export-var-number.src.js diff --git a/tests/fixtures/modules/export/export-var.result.js b/tests/fixtures/ecma-features/modules/export-var.result.js similarity index 100% rename from tests/fixtures/modules/export/export-var.result.js rename to tests/fixtures/ecma-features/modules/export-var.result.js diff --git a/tests/fixtures/modules/export/export-var.src.js b/tests/fixtures/ecma-features/modules/export-var.src.js similarity index 100% rename from tests/fixtures/modules/export/export-var.src.js rename to tests/fixtures/ecma-features/modules/export-var.src.js diff --git a/tests/fixtures/modules/import/import-default-and-named-specifiers.result.js b/tests/fixtures/ecma-features/modules/import-default-and-named-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/import/import-default-and-named-specifiers.result.js rename to tests/fixtures/ecma-features/modules/import-default-and-named-specifiers.result.js diff --git a/tests/fixtures/modules/import/import-default-and-named-specifiers.src.js b/tests/fixtures/ecma-features/modules/import-default-and-named-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/import/import-default-and-named-specifiers.src.js rename to tests/fixtures/ecma-features/modules/import-default-and-named-specifiers.src.js diff --git a/tests/fixtures/modules/import/import-default-and-namespace-specifiers.result.js b/tests/fixtures/ecma-features/modules/import-default-and-namespace-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/import/import-default-and-namespace-specifiers.result.js rename to tests/fixtures/ecma-features/modules/import-default-and-namespace-specifiers.result.js diff --git a/tests/fixtures/modules/import/import-default-and-namespace-specifiers.src.js b/tests/fixtures/ecma-features/modules/import-default-and-namespace-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/import/import-default-and-namespace-specifiers.src.js rename to tests/fixtures/ecma-features/modules/import-default-and-namespace-specifiers.src.js diff --git a/tests/fixtures/modules/import/import-default-as.result.js b/tests/fixtures/ecma-features/modules/import-default-as.result.js similarity index 100% rename from tests/fixtures/modules/import/import-default-as.result.js rename to tests/fixtures/ecma-features/modules/import-default-as.result.js diff --git a/tests/fixtures/modules/import/import-default-as.src.js b/tests/fixtures/ecma-features/modules/import-default-as.src.js similarity index 100% rename from tests/fixtures/modules/import/import-default-as.src.js rename to tests/fixtures/ecma-features/modules/import-default-as.src.js diff --git a/tests/fixtures/modules/import/import-default.result.js b/tests/fixtures/ecma-features/modules/import-default.result.js similarity index 100% rename from tests/fixtures/modules/import/import-default.result.js rename to tests/fixtures/ecma-features/modules/import-default.result.js diff --git a/tests/fixtures/modules/import/import-default.src.js b/tests/fixtures/ecma-features/modules/import-default.src.js similarity index 100% rename from tests/fixtures/modules/import/import-default.src.js rename to tests/fixtures/ecma-features/modules/import-default.src.js diff --git a/tests/fixtures/modules/import/import-jquery.result.js b/tests/fixtures/ecma-features/modules/import-jquery.result.js similarity index 100% rename from tests/fixtures/modules/import/import-jquery.result.js rename to tests/fixtures/ecma-features/modules/import-jquery.result.js diff --git a/tests/fixtures/modules/import/import-jquery.src.js b/tests/fixtures/ecma-features/modules/import-jquery.src.js similarity index 100% rename from tests/fixtures/modules/import/import-jquery.src.js rename to tests/fixtures/ecma-features/modules/import-jquery.src.js diff --git a/tests/fixtures/modules/import/import-module.result.js b/tests/fixtures/ecma-features/modules/import-module.result.js similarity index 100% rename from tests/fixtures/modules/import/import-module.result.js rename to tests/fixtures/ecma-features/modules/import-module.result.js diff --git a/tests/fixtures/modules/import/import-module.src.js b/tests/fixtures/ecma-features/modules/import-module.src.js similarity index 100% rename from tests/fixtures/modules/import/import-module.src.js rename to tests/fixtures/ecma-features/modules/import-module.src.js diff --git a/tests/fixtures/modules/import/import-named-as-specifier.result.js b/tests/fixtures/ecma-features/modules/import-named-as-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/import-named-as-specifier.result.js rename to tests/fixtures/ecma-features/modules/import-named-as-specifier.result.js diff --git a/tests/fixtures/modules/import/import-named-as-specifier.src.js b/tests/fixtures/ecma-features/modules/import-named-as-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/import-named-as-specifier.src.js rename to tests/fixtures/ecma-features/modules/import-named-as-specifier.src.js diff --git a/tests/fixtures/modules/import/import-named-as-specifiers.result.js b/tests/fixtures/ecma-features/modules/import-named-as-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/import/import-named-as-specifiers.result.js rename to tests/fixtures/ecma-features/modules/import-named-as-specifiers.result.js diff --git a/tests/fixtures/modules/import/import-named-as-specifiers.src.js b/tests/fixtures/ecma-features/modules/import-named-as-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/import/import-named-as-specifiers.src.js rename to tests/fixtures/ecma-features/modules/import-named-as-specifiers.src.js diff --git a/tests/fixtures/modules/import/import-named-empty.result.js b/tests/fixtures/ecma-features/modules/import-named-empty.result.js similarity index 100% rename from tests/fixtures/modules/import/import-named-empty.result.js rename to tests/fixtures/ecma-features/modules/import-named-empty.result.js diff --git a/tests/fixtures/modules/import/import-named-empty.src.js b/tests/fixtures/ecma-features/modules/import-named-empty.src.js similarity index 100% rename from tests/fixtures/modules/import/import-named-empty.src.js rename to tests/fixtures/ecma-features/modules/import-named-empty.src.js diff --git a/tests/fixtures/modules/import/import-named-specifier.result.js b/tests/fixtures/ecma-features/modules/import-named-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/import-named-specifier.result.js rename to tests/fixtures/ecma-features/modules/import-named-specifier.result.js diff --git a/tests/fixtures/modules/import/import-named-specifier.src.js b/tests/fixtures/ecma-features/modules/import-named-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/import-named-specifier.src.js rename to tests/fixtures/ecma-features/modules/import-named-specifier.src.js diff --git a/tests/fixtures/modules/import/import-named-specifiers.result.js b/tests/fixtures/ecma-features/modules/import-named-specifiers.result.js similarity index 100% rename from tests/fixtures/modules/import/import-named-specifiers.result.js rename to tests/fixtures/ecma-features/modules/import-named-specifiers.result.js diff --git a/tests/fixtures/modules/import/import-named-specifiers.src.js b/tests/fixtures/ecma-features/modules/import-named-specifiers.src.js similarity index 100% rename from tests/fixtures/modules/import/import-named-specifiers.src.js rename to tests/fixtures/ecma-features/modules/import-named-specifiers.src.js diff --git a/tests/fixtures/modules/import/import-namespace-specifier.result.js b/tests/fixtures/ecma-features/modules/import-namespace-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/import-namespace-specifier.result.js rename to tests/fixtures/ecma-features/modules/import-namespace-specifier.result.js diff --git a/tests/fixtures/modules/import/import-namespace-specifier.src.js b/tests/fixtures/ecma-features/modules/import-namespace-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/import-namespace-specifier.src.js rename to tests/fixtures/ecma-features/modules/import-namespace-specifier.src.js diff --git a/tests/fixtures/modules/import/import-null-as-nil.result.js b/tests/fixtures/ecma-features/modules/import-null-as-nil.result.js similarity index 100% rename from tests/fixtures/modules/import/import-null-as-nil.result.js rename to tests/fixtures/ecma-features/modules/import-null-as-nil.result.js diff --git a/tests/fixtures/modules/import/import-null-as-nil.src.js b/tests/fixtures/ecma-features/modules/import-null-as-nil.src.js similarity index 100% rename from tests/fixtures/modules/import/import-null-as-nil.src.js rename to tests/fixtures/ecma-features/modules/import-null-as-nil.src.js diff --git a/tests/fixtures/modules/export/invalid-export-batch-missing-from-clause.result.js b/tests/fixtures/ecma-features/modules/invalid-export-batch-missing-from-clause.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-batch-missing-from-clause.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-batch-missing-from-clause.result.js diff --git a/tests/fixtures/modules/export/invalid-export-batch-missing-from-clause.src.js b/tests/fixtures/ecma-features/modules/invalid-export-batch-missing-from-clause.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-batch-missing-from-clause.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-batch-missing-from-clause.src.js diff --git a/tests/fixtures/modules/export/invalid-export-batch-token.result.js b/tests/fixtures/ecma-features/modules/invalid-export-batch-token.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-batch-token.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-batch-token.result.js diff --git a/tests/fixtures/modules/export/invalid-export-batch-token.src.js b/tests/fixtures/ecma-features/modules/invalid-export-batch-token.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-batch-token.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-batch-token.src.js diff --git a/tests/fixtures/modules/export/invalid-export-default-equal.result.js b/tests/fixtures/ecma-features/modules/invalid-export-default-equal.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default-equal.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-default-equal.result.js diff --git a/tests/fixtures/modules/export/invalid-export-default-equal.src.js b/tests/fixtures/ecma-features/modules/invalid-export-default-equal.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default-equal.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-default-equal.src.js diff --git a/tests/fixtures/modules/export/invalid-export-default-token.result.js b/tests/fixtures/ecma-features/modules/invalid-export-default-token.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default-token.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-default-token.result.js diff --git a/tests/fixtures/modules/export/invalid-export-default-token.src.js b/tests/fixtures/ecma-features/modules/invalid-export-default-token.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default-token.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-default-token.src.js diff --git a/tests/fixtures/modules/export/invalid-export-default.result.js b/tests/fixtures/ecma-features/modules/invalid-export-default.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-default.result.js diff --git a/tests/fixtures/modules/export/invalid-export-default.src.js b/tests/fixtures/ecma-features/modules/invalid-export-default.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-default.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-default.src.js diff --git a/tests/fixtures/modules/export/invalid-export-named-default.result.js b/tests/fixtures/ecma-features/modules/invalid-export-named-default.result.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-named-default.result.js rename to tests/fixtures/ecma-features/modules/invalid-export-named-default.result.js diff --git a/tests/fixtures/modules/export/invalid-export-named-default.src.js b/tests/fixtures/ecma-features/modules/invalid-export-named-default.src.js similarity index 100% rename from tests/fixtures/modules/export/invalid-export-named-default.src.js rename to tests/fixtures/ecma-features/modules/invalid-export-named-default.src.js diff --git a/tests/fixtures/modules/import/invalid-import-default-after-named-after-default.result.js b/tests/fixtures/ecma-features/modules/invalid-import-default-after-named-after-default.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-after-named-after-default.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-after-named-after-default.result.js diff --git a/tests/fixtures/modules/import/invalid-import-default-after-named-after-default.src.js b/tests/fixtures/ecma-features/modules/invalid-import-default-after-named-after-default.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-after-named-after-default.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-after-named-after-default.src.js diff --git a/tests/fixtures/modules/import/invalid-import-default-after-named.result.js b/tests/fixtures/ecma-features/modules/invalid-import-default-after-named.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-after-named.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-after-named.result.js diff --git a/tests/fixtures/modules/import/invalid-import-default-after-named.src.js b/tests/fixtures/ecma-features/modules/invalid-import-default-after-named.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-after-named.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-after-named.src.js diff --git a/tests/fixtures/modules/import/invalid-import-default-missing-module-specifier.result.js b/tests/fixtures/ecma-features/modules/invalid-import-default-missing-module-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-missing-module-specifier.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-missing-module-specifier.result.js diff --git a/tests/fixtures/modules/import/invalid-import-default-missing-module-specifier.src.js b/tests/fixtures/ecma-features/modules/invalid-import-default-missing-module-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-missing-module-specifier.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-missing-module-specifier.src.js diff --git a/tests/fixtures/modules/import/invalid-import-default-module-specifier.result.js b/tests/fixtures/ecma-features/modules/invalid-import-default-module-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-module-specifier.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-module-specifier.result.js diff --git a/tests/fixtures/modules/import/invalid-import-default-module-specifier.src.js b/tests/fixtures/ecma-features/modules/invalid-import-default-module-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default-module-specifier.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-default-module-specifier.src.js diff --git a/tests/fixtures/modules/import/invalid-import-default.result.js b/tests/fixtures/ecma-features/modules/invalid-import-default.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-default.result.js diff --git a/tests/fixtures/modules/import/invalid-import-default.src.js b/tests/fixtures/ecma-features/modules/invalid-import-default.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-default.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-default.src.js diff --git a/tests/fixtures/modules/import/invalid-import-missing-module-specifier.result.js b/tests/fixtures/ecma-features/modules/invalid-import-missing-module-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-missing-module-specifier.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-missing-module-specifier.result.js diff --git a/tests/fixtures/modules/import/invalid-import-missing-module-specifier.src.js b/tests/fixtures/ecma-features/modules/invalid-import-missing-module-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-missing-module-specifier.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-missing-module-specifier.src.js diff --git a/tests/fixtures/modules/import/invalid-import-module-specifier.result.js b/tests/fixtures/ecma-features/modules/invalid-import-module-specifier.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-module-specifier.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-module-specifier.result.js diff --git a/tests/fixtures/modules/import/invalid-import-module-specifier.src.js b/tests/fixtures/ecma-features/modules/invalid-import-module-specifier.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-module-specifier.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-module-specifier.src.js diff --git a/tests/fixtures/modules/import/invalid-import-named-after-named.result.js b/tests/fixtures/ecma-features/modules/invalid-import-named-after-named.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-after-named.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-after-named.result.js diff --git a/tests/fixtures/modules/import/invalid-import-named-after-named.src.js b/tests/fixtures/ecma-features/modules/invalid-import-named-after-named.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-after-named.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-after-named.src.js diff --git a/tests/fixtures/modules/import/invalid-import-named-after-namespace.result.js b/tests/fixtures/ecma-features/modules/invalid-import-named-after-namespace.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-after-namespace.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-after-namespace.result.js diff --git a/tests/fixtures/modules/import/invalid-import-named-after-namespace.src.js b/tests/fixtures/ecma-features/modules/invalid-import-named-after-namespace.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-after-namespace.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-after-namespace.src.js diff --git a/tests/fixtures/modules/import/invalid-import-named-as-missing-from.result.js b/tests/fixtures/ecma-features/modules/invalid-import-named-as-missing-from.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-as-missing-from.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-as-missing-from.result.js diff --git a/tests/fixtures/modules/import/invalid-import-named-as-missing-from.src.js b/tests/fixtures/ecma-features/modules/invalid-import-named-as-missing-from.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-named-as-missing-from.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-named-as-missing-from.src.js diff --git a/tests/fixtures/modules/import/invalid-import-namespace-after-named.result.js b/tests/fixtures/ecma-features/modules/invalid-import-namespace-after-named.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-namespace-after-named.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-namespace-after-named.result.js diff --git a/tests/fixtures/modules/import/invalid-import-namespace-after-named.src.js b/tests/fixtures/ecma-features/modules/invalid-import-namespace-after-named.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-namespace-after-named.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-namespace-after-named.src.js diff --git a/tests/fixtures/modules/import/invalid-import-namespace-missing-as.result.js b/tests/fixtures/ecma-features/modules/invalid-import-namespace-missing-as.result.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-namespace-missing-as.result.js rename to tests/fixtures/ecma-features/modules/invalid-import-namespace-missing-as.result.js diff --git a/tests/fixtures/modules/import/invalid-import-namespace-missing-as.src.js b/tests/fixtures/ecma-features/modules/invalid-import-namespace-missing-as.src.js similarity index 100% rename from tests/fixtures/modules/import/invalid-import-namespace-missing-as.src.js rename to tests/fixtures/ecma-features/modules/invalid-import-namespace-missing-as.src.js diff --git a/tests/lib/modules.js b/tests/lib/modules.js deleted file mode 100644 index a8be3d4a..00000000 --- a/tests/lib/modules.js +++ /dev/null @@ -1,148 +0,0 @@ -/** - * @fileoverview Tests for ECMA feature flags - * @author Nicholas C. Zakas - * @copyright 2014 Nicholas C. Zakas. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -var assert = require("chai").assert, - leche = require("leche"), - path = require("path"), - espree = require("../../espree"), - shelljs = require("shelljs"); - -// var espree = require("esprima-fb"); -//------------------------------------------------------------------------------ -// Setup -//------------------------------------------------------------------------------ - -var MODULES_IMPORT_DIR = "./tests/fixtures/modules/import"; -var MODULES_EXPORT_DIR = "./tests/fixtures/modules/export"; - -var testImportFiles = shelljs.find(MODULES_IMPORT_DIR).filter(function(filename) { - return filename.indexOf(".src.js") > -1; -}).map(function(filename) { - return filename.substring(MODULES_IMPORT_DIR.length - 1, filename.length - 7); // strip off ".src.js" -}); - -var testExportFiles = shelljs.find(MODULES_EXPORT_DIR).filter(function(filename) { - return filename.indexOf(".src.js") > -1; -}).map(function(filename) { - return filename.substring(MODULES_EXPORT_DIR.length - 1, filename.length - 7); // strip off ".src.js" -}); - - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -describe("modules", function() { - - leche.withData(testImportFiles, function(filename) { - // Uncomment and fill in filename to focus on a single file - // var filename = "jsx/invalid-matching-placeholder-in-closing-tag"; - var code = shelljs.cat(path.resolve(MODULES_IMPORT_DIR, filename) + ".src.js"); - - it("should parse import declarations correctly when sourceType is `module`", function() { - var expected = require(path.resolve(__dirname, "../../", MODULES_IMPORT_DIR, filename) + ".result.js"); - var result; - - try { - result = espree.parse(code, { - loc: true, - range: true, - sourceType: "module" - }); - } catch (ex) { - - // if the result is an error, create an error object so deepEqual works - if (expected.message || expected.description) { - var expectedError = new Error(expected.message || expected.description); - Object.keys(expected).forEach(function(key) { - expectedError[key] = expected[key]; - }); - expected = expectedError; - } - - result = ex; // if an error is thrown, match the error - } - assert.deepEqual(result, expected); - }); - - it("should throw an error for import declarations when sourceType is not `module`", function() { - assert.throws(function() { - espree.parse(code, { - loc: true, - range: true - }); - }); - }); - }); - - leche.withData(testExportFiles, function(filename) { - // Uncomment and fill in filename to focus on a single file - // var filename = "jsx/invalid-matching-placeholder-in-closing-tag"; - var code = shelljs.cat(path.resolve(MODULES_EXPORT_DIR, filename) + ".src.js"); - - it("should parse export declarations correctly when sourceType is `module`", function() { - var expected = require(path.resolve(__dirname, "../../", MODULES_EXPORT_DIR, filename) + ".result.js"); - var result; - - try { - result = espree.parse(code, { - loc: true, - range: true, - sourceType: "module" - }); - } catch (ex) { - - // if the result is an error, create an error object so deepEqual works - if (expected.message || expected.description) { - var expectedError = new Error(expected.message || expected.description); - Object.keys(expected).forEach(function(key) { - expectedError[key] = expected[key]; - }); - expected = expectedError; - } - - result = ex; // if an error is thrown, match the error - } - assert.deepEqual(result, expected); - }); - - it("should throw an error for export declarations when sourceType is not `module`", function() { - assert.throws(function() { - espree.parse(code, { - loc: true, - range: true - }); - }); - }); - }); - -});