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 { 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;
let i = parser.index;
const code = full_char_code_at(parser.template, i);
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)) {
@ -54,6 +61,12 @@ export default function read_context(parser: Parser): Pattern {
parser.index = i;
const pattern_string = parser.template.slice(start, i);
return (parse_expression_at(`${' '.repeat(start - 1)}(${pattern_string} = 1)`, start - 1) as any)
.left as Pattern;
try {
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": {
"type": "ArrayPattern",
"start": 18,
"end": 39,
"type": "ArrayPattern",
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 39
}
},
"elements": [
{
"type": "Identifier",
"start": 19,
"end": 22,
"type": "Identifier",
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 22
}
},
"name": "key"
},
{
"type": "Identifier",
"start": 24,
"end": 29,
"type": "Identifier",
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 29
}
},
"name": "value"
},
{
"type": "RestElement",
"start": 31,
"end": 38,
"type": "RestElement",
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 38
}
},
"argument": {
"type": "Identifier",
"start": 34,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 38
}
},
"name": "rest"
}
}

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

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

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

Loading…
Cancel
Save