From d5d4e7491de9a8b4e99128197534ca411aee2289 Mon Sep 17 00:00:00 2001 From: "William C. Johnson" Date: Sun, 16 Jul 2017 20:41:48 -0400 Subject: [PATCH] Allow placeholder to be changed via config --- src/options.js | 5 +- .../opts/change-placeholder/actual.js | 1 + .../expected.changePlaceholder.json | 64 ++++++++++++++++++ .../opts/change-placeholder/expected.json | 66 +++++++++++++++++++ .../opts/change-placeholder/options.json | 12 ++++ test/utils/TestRunner.js | 4 ++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/syntactic-placeholder/opts/change-placeholder/actual.js create mode 100644 test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.changePlaceholder.json create mode 100644 test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.json create mode 100644 test/fixtures/syntactic-placeholder/opts/change-placeholder/options.json diff --git a/src/options.js b/src/options.js index 72c65f34a6..513069be70 100755 --- a/src/options.js +++ b/src/options.js @@ -9,7 +9,8 @@ export const defaultOptions: { allowImportExportEverywhere: boolean, allowSuperOutsideMethod: boolean, plugins: Array, - strictMode: any + strictMode: any, + placeholder: string } = { // Source type ("script" or "module") for different semantics sourceType: "script", @@ -30,6 +31,8 @@ export const defaultOptions: { plugins: [], // TODO strictMode: null, + // Default placeholder for use with syntacticPlaceholder plugin + placeholder: "_" }; // Interpret and default an options object diff --git a/test/fixtures/syntactic-placeholder/opts/change-placeholder/actual.js b/test/fixtures/syntactic-placeholder/opts/change-placeholder/actual.js new file mode 100644 index 0000000000..52c184f186 --- /dev/null +++ b/test/fixtures/syntactic-placeholder/opts/change-placeholder/actual.js @@ -0,0 +1 @@ +P diff --git a/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.changePlaceholder.json b/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.changePlaceholder.json new file mode 100644 index 0000000000..dd674cdc43 --- /dev/null +++ b/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.changePlaceholder.json @@ -0,0 +1,64 @@ +{ + "type": "File", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "expression": { + "type": "PlaceholderExpression", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.json b/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.json new file mode 100644 index 0000000000..f254aba2d4 --- /dev/null +++ b/test/fixtures/syntactic-placeholder/opts/change-placeholder/expected.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "P" + }, + "name": "P" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/syntactic-placeholder/opts/change-placeholder/options.json b/test/fixtures/syntactic-placeholder/opts/change-placeholder/options.json new file mode 100644 index 0000000000..4674015b3c --- /dev/null +++ b/test/fixtures/syntactic-placeholder/opts/change-placeholder/options.json @@ -0,0 +1,12 @@ +{ + "alternatives": { + "changePlaceholder": { + "allPlugins": true, + "excludePlugins": ["estree"], + "expected": "expected.changePlaceholder.json", + "parserOpts": { + "placeholder": "P" + } + } + } +} diff --git a/test/utils/TestRunner.js b/test/utils/TestRunner.js index 55acd4e0dd..18a90bfa85 100644 --- a/test/utils/TestRunner.js +++ b/test/utils/TestRunner.js @@ -235,6 +235,10 @@ exports.Test = class Test { } } } + + if (alt.parserOpts) { + this.parserOpts = Object.assign({}, this.parserOpts, alt.parserOpts); + } } includePlugins(plugins, list) {