Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Allow plugins:["*"] #229

Merged
merged 2 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,24 @@ export default class Parser extends Tokenizer {
this[name] = f(this[name]);
}

loadPlugins(pluginList: Array<string>): Object {
loadAllPlugins() {
// ensure flow plugin loads last
const pluginNames = Object.keys(plugins).filter((name) => name !== "flow");
pluginNames.push("flow");

pluginNames.forEach((name) => {
let plugin = plugins[name];
if (plugin) plugin(this);
});
}

loadPlugins(pluginList: Array<string>): { [key: string]: boolean } {
if (pluginList.indexOf("*") >= 0) {
this.loadAllPlugins();

return { "*": true };
}

let pluginMap = {};

if (pluginList.indexOf("flow") >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/jsx/regression/test-*-option/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function A(): void {
a::b;
<div></div>;
}
277 changes: 277 additions & 0 deletions test/fixtures/jsx/regression/test-*-option/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
{
"type": "File",
"start": 0,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "A"
},
"name": "A"
},
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 12,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 18
}
},
"typeAnnotation": {
"type": "VoidTypeAnnotation",
"start": 14,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 18
}
}
}
},
"body": {
"type": "BlockStatement",
"start": 19,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 23,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 7
}
},
"expression": {
"type": "BindExpression",
"start": 23,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"object": {
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"callee": {
"type": "Identifier",
"start": 26,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "b"
},
"name": "b"
}
}
},
{
"type": "ExpressionStatement",
"start": 31,
"end": 43,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 14
}
},
"expression": {
"type": "JSXElement",
"start": 31,
"end": 42,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 13
}
},
"openingElement": {
"type": "JSXOpeningElement",
"start": 31,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 7
}
},
"attributes": [],
"name": {
"type": "JSXIdentifier",
"start": 32,
"end": 35,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 6
}
},
"name": "div"
},
"selfClosing": false
},
"closingElement": {
"type": "JSXClosingElement",
"start": 36,
"end": 42,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 13
}
},
"name": {
"type": "JSXIdentifier",
"start": 38,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 12
}
},
"name": "div"
}
},
"children": []
}
}
],
"directives": []
}
}
],
"directives": []
}
}
3 changes: 3 additions & 0 deletions test/fixtures/jsx/regression/test-*-option/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["*"]
}