|
|
|
@ -14,17 +14,16 @@ import { locator } from '../../../state.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('../index.js').Parser} parser
|
|
|
|
|
* @param {boolean} [optional_allowed]
|
|
|
|
|
* @returns {import('estree').Pattern}
|
|
|
|
|
*/
|
|
|
|
|
export default function read_pattern(parser, optional_allowed = false) {
|
|
|
|
|
export default function read_pattern(parser) {
|
|
|
|
|
const start = parser.index;
|
|
|
|
|
let i = parser.index;
|
|
|
|
|
|
|
|
|
|
const code = full_char_code_at(parser.template, i);
|
|
|
|
|
if (isIdentifierStart(code, true)) {
|
|
|
|
|
const name = /** @type {string} */ (parser.read_identifier());
|
|
|
|
|
const annotation = read_type_annotation(parser, optional_allowed);
|
|
|
|
|
const annotation = read_type_annotation(parser);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: 'Identifier',
|
|
|
|
@ -84,7 +83,7 @@ export default function read_pattern(parser, optional_allowed = false) {
|
|
|
|
|
parse_expression_at(`${space_with_newline}(${pattern_string} = 1)`, parser.ts, start - 1)
|
|
|
|
|
).left;
|
|
|
|
|
|
|
|
|
|
expression.typeAnnotation = read_type_annotation(parser, optional_allowed);
|
|
|
|
|
expression.typeAnnotation = read_type_annotation(parser);
|
|
|
|
|
if (expression.typeAnnotation) {
|
|
|
|
|
expression.end = expression.typeAnnotation.end;
|
|
|
|
|
}
|
|
|
|
@ -97,19 +96,12 @@ export default function read_pattern(parser, optional_allowed = false) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('../index.js').Parser} parser
|
|
|
|
|
* @param {boolean} [optional_allowed]
|
|
|
|
|
* @returns {any}
|
|
|
|
|
*/
|
|
|
|
|
function read_type_annotation(parser, optional_allowed = false) {
|
|
|
|
|
function read_type_annotation(parser) {
|
|
|
|
|
const start = parser.index;
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
if (optional_allowed && parser.eat('?')) {
|
|
|
|
|
// Acorn-TS puts the optional info as a property on the surrounding node.
|
|
|
|
|
// We spare the work here because it doesn't matter for us anywhere else.
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!parser.eat(':')) {
|
|
|
|
|
parser.index = start;
|
|
|
|
|
return undefined;
|
|
|
|
|