fix failed test

pull/4596/head
Tan Li Hau 6 years ago
parent 9cf08e4597
commit 2814b1d9c2

@ -10,13 +10,20 @@ import {
import { parse_expression_at } from "../acorn"; import { parse_expression_at } from "../acorn";
import { Pattern } from "estree"; import { Pattern } from "estree";
export default function read_context(parser: Parser): Pattern { export default function read_context(
parser: Parser
): Pattern & { start: number; end: number } {
const start = parser.index; const start = parser.index;
let i = parser.index; let i = parser.index;
const code = full_char_code_at(parser.template, i); const code = full_char_code_at(parser.template, i);
if (isIdentifierStart(code, true)) { if (isIdentifierStart(code, true)) {
return { type: "Identifier", name: parser.read_identifier() }; return {
type: "Identifier",
name: parser.read_identifier(),
start,
end: parser.index
};
} }
if (!is_bracket_open(code)) { if (!is_bracket_open(code)) {
@ -54,6 +61,12 @@ export default function read_context(parser: Parser): Pattern {
parser.index = i; parser.index = i;
const pattern_string = parser.template.slice(start, i); const pattern_string = parser.template.slice(start, i);
return (parse_expression_at(`${' '.repeat(start - 1)}(${pattern_string} = 1)`, start - 1) as any) try {
.left as Pattern; return (parse_expression_at(
`${" ".repeat(start - 1)}(${pattern_string} = 1)`,
start - 1
) as any).left;
} catch (error) {
parser.acorn_error(error);
}
} }

@ -85,30 +85,80 @@
} }
], ],
"context": { "context": {
"type": "ArrayPattern",
"start": 18, "start": 18,
"end": 39, "end": 39,
"type": "ArrayPattern", "loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 39
}
},
"elements": [ "elements": [
{ {
"type": "Identifier",
"start": 19, "start": 19,
"end": 22, "end": 22,
"type": "Identifier", "loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 22
}
},
"name": "key" "name": "key"
}, },
{ {
"type": "Identifier",
"start": 24, "start": 24,
"end": 29, "end": 29,
"type": "Identifier", "loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 29
}
},
"name": "value" "name": "value"
}, },
{ {
"type": "RestElement",
"start": 31, "start": 31,
"end": 38, "end": 38,
"type": "RestElement", "loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 38
}
},
"argument": { "argument": {
"type": "Identifier", "type": "Identifier",
"start": 34, "start": 34,
"end": 38, "end": 38,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 38
}
},
"name": "rest" "name": "rest"
} }
} }

@ -1,5 +1,5 @@
[{ [{
"code": "comma-after-rest", "code": "parse-error",
"message": "Comma is not permitted after the rest element", "message": "Comma is not permitted after the rest element",
"pos": 100, "pos": 100,
"start": { "start": {

@ -1,6 +1,6 @@
[{ [{
"code": "unexpected-reserved-word", "code": "parse-error",
"message": "'case' is a reserved word in JavaScript and cannot be used here", "message": "Unexpected keyword 'case'",
"start": { "start": {
"line": 1, "line": 1,
"column": 18, "column": 18,

@ -1,6 +1,6 @@
[{ [{
"code": "unexpected-reserved-word", "code": "parse-error",
"message": "'case' is a reserved word in JavaScript and cannot be used here", "message": "Unexpected token",
"start": { "start": {
"line": 1, "line": 1,
"column": 17, "column": 17,

Loading…
Cancel
Save