|
|
@ -20,7 +20,7 @@ type Property = {
|
|
|
|
type Context = {
|
|
|
|
type Context = {
|
|
|
|
start: number;
|
|
|
|
start: number;
|
|
|
|
end: number;
|
|
|
|
end: number;
|
|
|
|
type: 'Identifier' | 'ArrayPattern' | 'ObjectPattern';
|
|
|
|
type: 'Identifier' | 'ArrayPattern' | 'ObjectPattern' | 'RestIdentifier';
|
|
|
|
name?: string;
|
|
|
|
name?: string;
|
|
|
|
elements?: Context[];
|
|
|
|
elements?: Context[];
|
|
|
|
properties?: Property[];
|
|
|
|
properties?: Property[];
|
|
|
@ -35,6 +35,13 @@ function error_on_assignment_pattern(parser: Parser) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function error_on_rest_pattern_not_last(parser: Parser) {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: 'rest-pattern-not-last',
|
|
|
|
|
|
|
|
message: 'Rest destructuring expected to be last'
|
|
|
|
|
|
|
|
}, parser.index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function read_context(parser: Parser) {
|
|
|
|
export default function read_context(parser: Parser) {
|
|
|
|
const context: Context = {
|
|
|
|
const context: Context = {
|
|
|
|
start: parser.index,
|
|
|
|
start: parser.index,
|
|
|
@ -49,6 +56,11 @@ export default function read_context(parser: Parser) {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastContext = context.elements[context.elements.length - 1];
|
|
|
|
|
|
|
|
if (lastContext && lastContext.type === 'RestIdentifier') {
|
|
|
|
|
|
|
|
error_on_rest_pattern_not_last(parser);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.template[parser.index] === ',') {
|
|
|
|
if (parser.template[parser.index] === ',') {
|
|
|
|
context.elements.push(null);
|
|
|
|
context.elements.push(null);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -103,6 +115,22 @@ export default function read_context(parser: Parser) {
|
|
|
|
context.end = parser.index;
|
|
|
|
context.end = parser.index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (parser.eat('...')) {
|
|
|
|
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
|
|
|
|
context.type = 'RestIdentifier';
|
|
|
|
|
|
|
|
context.end = parser.index;
|
|
|
|
|
|
|
|
context.name = name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: 'invalid-context',
|
|
|
|
|
|
|
|
message: 'Expected a rest pattern'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
if (name) {
|
|
|
|
if (name) {
|
|
|
|