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

Commit

Permalink
Merge branch 'master' into 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Feb 20, 2017
2 parents a4bf244 + b023470 commit 7bf553a
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ pp.estreeParseRegExpLiteral = function ({ pattern, flags }) {
};

pp.estreeParseLiteral = function (value) {
const node = this.parseLiteral(value, "Literal");
node.raw = node.extra.raw;
delete node.extra;

return node;
return this.parseLiteral(value, "Literal");
};

pp.directiveToStmt = function (directive) {
Expand Down Expand Up @@ -177,6 +173,16 @@ export default function (instance) {
};
});

instance.extend("parseLiteral", function(inner) {
return function (...args) {
const node = inner.call(this, ...args);
node.raw = node.extra.raw;
delete node.extra;

return node;
};
});

instance.extend("parseMethod", function(inner) {
return function (node, ...args) {
let funcNode = this.startNode();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x: "string";
116 changes: 116 additions & 0 deletions test/fixtures/estree/flow/string-literal-annotation/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"type": "File",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"program": {
"type": "Program",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 15
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 5,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 15
}
},
"typeAnnotation": {
"type": "StringLiteralTypeAnnotation",
"start": 7,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 15
}
},
"value": "string",
"raw": "\"string\""
}
}
},
"init": null
}
],
"kind": "var"
}
]
}
}

0 comments on commit 7bf553a

Please sign in to comment.