Implement named backreference parsing
MODIFY
packages/@romejs/codec-js-regexp/index.ts
packages/@romejs/codec-js-regexp/index.ts
@@ -72,8 +72,8 @@ type Tokens =
escaped: boolean;
}
>;
- NamedBackReference: ComplexToken<
- 'NamedBackReference',
+ NamedBackReferenceCharacter: ComplexToken<
+ 'NamedBackReferenceCharacter',
{
value: string;
escaped: boolean;
@@ -232,7 +232,7 @@ export const createRegExpParser = createParser((ParserCore) =>
// skip the closing >
namedBackReferenceIndex++;
}
- return this.finishComplexToken('NamedBackReference', {
+ return this.finishComplexToken('NamedBackReferenceCharacter', {
value: namedBackReference,
escaped: true,
}, coerce0(namedBackReferenceIndex));
@@ -626,6 +626,16 @@ export const createRegExpParser = createParser((ParserCore) =>
};
}
+ if (token.type === 'NamedBackReferenceCharacter') {
+ this.nextToken();
+
+ return {
+ type: 'RegExpNamedBackReference',
+ name: token.value,
+ loc: this.finishLocFromToken(token),
+ };
+ }
+
if (token.type === 'EscapedCharacter') {
this.nextToken();
@@ -926,13 +936,8 @@ export const createRegExpParser = createParser((ParserCore) =>
case 'EscapedCharacter':
case 'Character':
case 'NumericBackReferenceCharacter':
+ case 'NamedBackReferenceCharacter':
return this.parseCharacter();
-
- case 'NamedBackReference': {
- this.nextToken();
- console.log(token.value, ' : ', token.end);
- return undefined;
- }
}
this.addDiagnostic({

MODIFY
packages/@romejs/js-analysis/evaluators/index.ts
packages/@romejs/js-analysis/evaluators/index.ts
@@ -17,11 +17,9 @@ const evaluators: Map<string, (node: AnyNode, scope: Scope, hub: Hub) =>
export default evaluators;
// EVERYTHING BELOW IS AUTOGENERATED. SEE SCRIPTS FOLDER FOR UPDATE SCRIPTS
+
import AmbiguousFlowTypeCastExpression from './temp/AmbiguousFlowTypeCastExpression';
-evaluators.set(
- 'AmbiguousFlowTypeCastExpression',
- AmbiguousFlowTypeCastExpression,
-);
+evaluators.set('AmbiguousFlowTypeCastExpression', AmbiguousFlowTypeCastExpression);
import AnyKeywordTypeAnnotation from './types/AnyKeywordTypeAnnotation';
evaluators.set('AnyKeywordTypeAnnotation', AnyKeywordTypeAnnotation);
@@ -48,10 +46,7 @@ import AssignmentObjectPattern from './patterns/AssignmentObjectPattern';
evaluators.set('AssignmentObjectPattern', AssignmentObjectPattern);
import AssignmentObjectPatternProperty from './patterns/AssignmentObjectPatternProperty';
-evaluators.set(
- 'AssignmentObjectPatternProperty',
- AssignmentObjectPatternProperty,
-);
+evaluators.set('AssignmentObjectPatternProperty', AssignmentObjectPatternProperty);
import AwaitExpression from './expressions/AwaitExpression';
evaluators.set('AwaitExpression', AwaitExpression);
@@ -491,6 +486,9 @@ evaluators.set('RegExpGroupNonCapture', RegExpGroupNonCapture);
import RegExpLiteral from './literals/RegExpLiteral';
evaluators.set('RegExpLiteral', RegExpLiteral);
+import RegExpNamedBackReference from './regex/RegExpNamedBackReference';
+evaluators.set('RegExpNamedBackReference', RegExpNamedBackReference);
+
import RegExpNonDigitCharacter from './regex/RegExpNonDigitCharacter';
evaluators.set('RegExpNonDigitCharacter', RegExpNonDigitCharacter);
@@ -609,10 +607,7 @@ import TSConstructorType from './typescript/TSConstructorType';
evaluators.set('TSConstructorType', TSConstructorType);
import TSConstructSignatureDeclaration from './typescript/TSConstructSignatureDeclaration';
-evaluators.set(
- 'TSConstructSignatureDeclaration',
- TSConstructSignatureDeclaration,
-);
+evaluators.set('TSConstructSignatureDeclaration', TSConstructSignatureDeclaration);
import TSDeclareFunction from './typescript/TSDeclareFunction';
evaluators.set('TSDeclareFunction', TSDeclareFunction);

ADD
packages/@romejs/js-analysis/evaluators/regex/RegExpNamedBackReference.ts
+/**
+* Copyright (c) Facebook, Inc. and its affiliates.
+*
+* This source code is licensed under the MIT license found in the
+* LICENSE file in the root directory of this source tree.
+*/
+
+import {AnyNode, RegExpNamedBackReference, regExpNamedBackReference} from '@romejs/js-ast';
+
+export default function RegExpNamedBackReference(node: AnyNode) {
+ node = regExpNamedBackReference.assert(node);
+ throw new Error('unimplemented');
+}
+
\ No newline at end of file

MODIFY
packages/@romejs/js-ast/index.ts
packages/@romejs/js-ast/index.ts
@@ -15,494 +15,251 @@ export * from './constants';
export * from './unions';
// EVERYTHING BELOW IS AUTOGENERATED. SEE SCRIPTS FOLDER FOR UPDATE SCRIPTS
-export * from './temp/AmbiguousFlowTypeCastExpression';
+export * from './temp/AmbiguousFlowTypeCastExpression';
export * from './types/AnyKeywordTypeAnnotation';
-
export * from './expressions/ArrayExpression';
-
export * from './expressions/ArrowFunctionExpression';
-
export * from './patterns/AssignmentArrayPattern';
-
export * from './patterns/AssignmentAssignmentPattern';
-
export * from './expressions/AssignmentExpression';
-
export * from './patterns/AssignmentIdentifier';
-
export * from './patterns/AssignmentObjectPattern';
-
export * from './patterns/AssignmentObjectPatternProperty';
-
export * from './expressions/AwaitExpression';
-
export * from './types/BigIntKeywordTypeAnnotation';
-
export * from './literals/BigIntLiteral';
-
export * from './expressions/BinaryExpression';
-
export * from './patterns/BindingArrayPattern';
-
export * from './patterns/BindingAssignmentPattern';
-
export * from './patterns/BindingIdentifier';
-
export * from './patterns/BindingObjectPattern';
-
export * from './patterns/BindingObjectPatternProperty';
-
export * from './statements/BlockStatement';
-
export * from './types/BooleanKeywordTypeAnnotation';
-
export * from './literals/BooleanLiteral';
-
export * from './types/BooleanLiteralTypeAnnotation';
-
export * from './statements/BreakStatement';
-
export * from './expressions/CallExpression';
-
export * from './auxiliary/CatchClause';
-
export * from './classes/ClassDeclaration';
-
export * from './classes/ClassExpression';
-
export * from './classes/ClassHead';
-
export * from './classes/ClassMethod';
-
export * from './classes/ClassPrivateMethod';
-
export * from './classes/ClassPrivateProperty';
-
export * from './classes/ClassProperty';
-
export * from './classes/ClassPropertyMeta';
-
export * from './core/CommentBlock';
-
export * from './core/CommentLine';
-
export * from './auxiliary/ComputedMemberProperty';
-
export * from './objects/ComputedPropertyKey';
-
export * from './expressions/ConditionalExpression';
-
export * from './statements/ContinueStatement';
-
export * from './statements/DebuggerStatement';
-
export * from './core/Directive';
-
export * from './expressions/DoExpression';
-
export * from './statements/DoWhileStatement';
-
export * from './types/EmptyKeywordTypeAnnotation';
-
export * from './statements/EmptyStatement';
-
export * from './modules/ExportAllDeclaration';
-
export * from './modules/ExportDefaultDeclaration';
-
export * from './modules/ExportDefaultSpecifier';
-
export * from './modules/ExportExternalDeclaration';
-
export * from './modules/ExportExternalSpecifier';
-
export * from './modules/ExportLocalDeclaration';
-
export * from './modules/ExportLocalSpecifier';
-
export * from './modules/ExportNamespaceSpecifier';
-
export * from './statements/ExpressionStatement';
-
export * from './flow/FlowArrayTypeAnnotation';
-
export * from './flow/FlowClassImplements';
-
export * from './flow/FlowDeclareClass';
-
export * from './flow/FlowDeclaredPredicate';
-
export * from './flow/FlowDeclareExportAll';
-
export * from './flow/FlowDeclareExportDefault';
-
export * from './flow/FlowDeclareExportNamed';
-
export * from './flow/FlowDeclareFunction';
-
export * from './flow/FlowDeclareInterface';
-
export * from './flow/FlowDeclareModule';
-
export * from './flow/FlowDeclareModuleExports';
-
export * from './flow/FlowDeclareOpaqueType';
-
export * from './flow/FlowDeclareVariable';
-
export * from './flow/FlowExistsTypeAnnotation';
-
export * from './flow/FlowFunctionTypeAnnotation';
-
export * from './flow/FlowFunctionTypeParam';
-
export * from './flow/FlowGenericTypeAnnotation';
-
export * from './flow/FlowInferredPredicate';
-
export * from './flow/FlowInterface';
-
export * from './flow/FlowInterfaceDeclaration';
-
export * from './flow/FlowInterfaceExtends';
-
export * from './flow/FlowInterfaceTypeAnnotation';
-
export * from './flow/FlowNullableTypeAnnotation';
-
export * from './flow/FlowNumericLiteral';
-
export * from './flow/FlowObjectTypeAnnotation';
-
export * from './flow/FlowObjectTypeCallProperty';
-
export * from './flow/FlowObjectTypeIndexer';
-
export * from './flow/FlowObjectTypeInternalSlot';
-
export * from './flow/FlowObjectTypeProperty';
-
export * from './flow/FlowObjectTypeSpreadProperty';
-
export * from './flow/FlowOpaqueType';
-
export * from './flow/FlowQualifiedTypeIdentifier';
-
export * from './flow/FlowThisTypeAnnotation';
-
export * from './flow/FlowTupleTypeAnnotation';
-
export * from './flow/FlowTypeCastExpression';
-
export * from './flow/FlowTypeofTypeAnnotation';
-
export * from './flow/FlowTypeParameter';
-
export * from './flow/FlowTypeParameterDeclaration';
-
export * from './flow/FlowTypeParameterInstantiation';
-
export * from './flow/FlowVariance';
-
export * from './statements/ForInStatement';
-
export * from './statements/ForOfStatement';
-
export * from './statements/ForStatement';
-
export * from './statements/FunctionDeclaration';
-
export * from './expressions/FunctionExpression';
-
export * from './auxiliary/FunctionHead';
-
export * from './auxiliary/Identifier';
-
export * from './statements/IfStatement';
-
export * from './modules/ImportCall';
-
export * from './modules/ImportDeclaration';
-
export * from './modules/ImportDefaultSpecifier';
-
export * from './modules/ImportNamespaceSpecifier';
-
export * from './modules/ImportSpecifier';
-
export * from './modules/ImportSpecifierLocal';
-
export * from './core/InterpreterDirective';
-
export * from './types/IntersectionTypeAnnotation';
-
export * from './jsx/JSXAttribute';
-
export * from './jsx/JSXElement';
-
export * from './jsx/JSXEmptyExpression';
-
export * from './jsx/JSXExpressionContainer';
-
export * from './jsx/JSXFragment';
-
export * from './jsx/JSXIdentifier';
-
export * from './jsx/JSXMemberExpression';
-
export * from './jsx/JSXNamespacedName';
-
export * from './jsx/JSXReferenceIdentifier';
-
export * from './jsx/JSXSpreadAttribute';
-
export * from './jsx/JSXSpreadChild';
-
export * from './jsx/JSXText';
-
export * from './statements/LabeledStatement';
-
export * from './expressions/LogicalExpression';
-
export * from './expressions/MemberExpression';
-
export * from './expressions/MetaProperty';
-
export * from './types/MixedKeywordTypeAnnotation';
-
export * from './temp/MockParent';
-
export * from './types/NeverKeywordTypeAnnotation';
-
export * from './expressions/NewExpression';
-
export * from './types/NullKeywordTypeAnnotation';
-
export * from './literals/NullLiteral';
-
export * from './types/NumberKeywordTypeAnnotation';
-
export * from './literals/NumericLiteral';
-
export * from './types/NumericLiteralTypeAnnotation';
-
export * from './objects/ObjectExpression';
-
export * from './types/ObjectKeywordTypeAnnotation';
-
export * from './objects/ObjectMethod';
-
export * from './objects/ObjectProperty';
-
export * from './expressions/OptionalCallExpression';
-
export * from './patterns/PatternMeta';
-
export * from './classes/PrivateName';
-
export * from './core/Program';
-
export * from './expressions/ReferenceIdentifier';
-
export * from './regex/RegExpAlternation';
-
export * from './regex/RegExpAnyCharacter';
-
export * from './regex/RegExpCharacter';
-
export * from './regex/RegExpCharSet';
-
export * from './regex/RegExpCharSetRange';
-
export * from './regex/RegExpControlCharacter';
-
export * from './regex/RegExpDigitCharacter';
-
export * from './regex/RegExpEndCharacter';
-
export * from './regex/RegExpGroupCapture';
-
export * from './regex/RegExpGroupNonCapture';
-
export * from './literals/RegExpLiteral';
-
+export * from './regex/RegExpNamedBackReference';
export * from './regex/RegExpNonDigitCharacter';
-
export * from './regex/RegExpNonWhiteSpaceCharacter';
-
export * from './regex/RegExpNonWordBoundaryCharacter';
-
export * from './regex/RegExpNonWordCharacter';
-
export * from './regex/RegExpNumericBackReference';
-
export * from './regex/RegExpQuantified';
-
export * from './regex/RegExpStartCharacter';
-
export * from './regex/RegExpSubExpression';
-
export * from './regex/RegExpWhiteSpaceCharacter';
-
export * from './regex/RegExpWordBoundaryCharacter';
-
export * from './regex/RegExpWordCharacter';
-
export * from './statements/ReturnStatement';
-
export * from './expressions/SequenceExpression';
-
export * from './auxiliary/SpreadElement';
-
export * from './objects/SpreadProperty';
-
export * from './auxiliary/StaticMemberProperty';
-
export * from './objects/StaticPropertyKey';
-
export * from './types/StringKeywordTypeAnnotation';
-
export * from './literals/StringLiteral';
-
export * from './types/StringLiteralTypeAnnotation';
-
export * from './expressions/Super';
-
export * from './auxiliary/SwitchCase';
-
export * from './statements/SwitchStatement';
-
export * from './types/SymbolKeywordTypeAnnotation';
-
export * from './expressions/TaggedTemplateExpression';
-
export * from './auxiliary/TemplateElement';
-
export * from './literals/TemplateLiteral';
-
export * from './types/TemplateLiteralTypeAnnotation';
-
export * from './expressions/ThisExpression';
-
export * from './statements/ThrowStatement';
-
export * from './statements/TryStatement';
-
export * from './typescript/TSArrayType';
-
export * from './typescript/TSAsExpression';
-
export * from './typescript/TSAssignmentAsExpression';
-
export * from './typescript/TSAssignmentNonNullExpression';
-
export * from './typescript/TSAssignmentTypeAssertion';
-
export * from './typescript/TSCallSignatureDeclaration';
-
export * from './typescript/TSConditionalType';
-
export * from './typescript/TSConstructorType';
-
export * from './typescript/TSConstructSignatureDeclaration';
-
export * from './typescript/TSDeclareFunction';
-
export * from './typescript/TSDeclareMethod';
-
export * from './typescript/TSEnumDeclaration';
-
export * from './typescript/TSEnumMember';
-
export * from './typescript/TSExportAssignment';
-
export * from './typescript/TSExpressionWithTypeArguments';
-
export * from './typescript/TSExternalModuleReference';
-
export * from './typescript/TSFunctionType';
-
export * from './typescript/TSImportEqualsDeclaration';
-
export * from './typescript/TSImportType';
-
export * from './typescript/TSIndexedAccessType';
-
export * from './typescript/TSIndexSignature';
-
export * from './typescript/TSInferType';
-
export * from './typescript/TSInterfaceBody';
-
export * from './typescript/TSInterfaceDeclaration';
-
export * from './typescript/TSMappedType';
-
export * from './typescript/TSMethodSignature';
-
export * from './typescript/TSModuleBlock';
-
export * from './typescript/TSModuleDeclaration';
-
export * from './typescript/TSNamespaceExportDeclaration';
-
export * from './typescript/TSNonNullExpression';
-
export * from './typescript/TSOptionalType';
-
export * from './typescript/TSParenthesizedType';
-
export * from './typescript/TSPropertySignature';
-
export * from './typescript/TSQualifiedName';
-
export * from './typescript/TSSignatureDeclarationMeta';
-
export * from './typescript/TSThisType';
-
export * from './typescript/TSTupleType';
-
export * from './typescript/TSTypeAssertion';
-
export * from './typescript/TSTypeLiteral';
-
export * from './typescript/TSTypeOperator';
-
export * from './typescript/TSTypeParameter';
-
export * from './typescript/TSTypeParameterDeclaration';
-
export * from './typescript/TSTypeParameterInstantiation';
-
export * from './typescript/TSTypePredicate';
-
export * from './typescript/TSTypeQuery';
-
export * from './typescript/TSTypeReference';
-
export * from './types/TypeAliasTypeAnnotation';
-
export * from './expressions/UnaryExpression';
-
export * from './types/UndefinedKeywordTypeAnnotation';
-
export * from './types/UnionTypeAnnotation';
-
export * from './types/UnknownKeywordTypeAnnotation';
-
export * from './expressions/UpdateExpression';
-
export * from './auxiliary/VariableDeclaration';
-
export * from './statements/VariableDeclarationStatement';
-
export * from './auxiliary/VariableDeclarator';
-
export * from './types/VoidKeywordTypeAnnotation';
-
export * from './statements/WhileStatement';
-
export * from './statements/WithStatement';
-
export * from './expressions/YieldExpression';

ADD
packages/@romejs/js-ast/regex/RegExpNamedBackReference.ts
+/**
+* Copyright (c) Facebook, Inc. and its affiliates.
+*
+* This source code is licensed under the MIT license found in the
+* LICENSE file in the root directory of this source tree.
+*/
+
+import {JSNodeBase} from '../index';
+import {createBuilder} from '../utils';
+
+export type RegExpNamedBackReference = JSNodeBase & {
+ type: 'RegExpNamedBackReference';
+ name: string,
+};
+
+export const regExpNamedBackReference = createBuilder<RegExpNamedBackReference>('RegExpNamedBackReference', {
+ bindingKeys: {},
+ visitorKeys: {},
+});

MODIFY
packages/@romejs/js-ast/unions.ts
packages/@romejs/js-ast/unions.ts
@@ -353,6 +353,7 @@ export type AnyRegExpEscapedCharacter =
| n.RegExpDigitCharacter
| n.RegExpNonDigitCharacter
| n.RegExpWordBoundaryCharacter
+ | n.RegExpNamedBackReference
| n.RegExpNonWordBoundaryCharacter
| n.RegExpNumericBackReference
| n.RegExpWhiteSpaceCharacter
@@ -386,6 +387,7 @@ export type AnyRegExpBodyItem =
export type AnyRegExpExpression = n.RegExpSubExpression | n.RegExpAlternation;
// EVERYTHING BELOW IS AUTOGENERATED. SEE SCRIPTS FOLDER FOR UPDATE SCRIPTS
+
export type AnyNode =
| n.AmbiguousFlowTypeCastExpression
| n.AnyKeywordTypeAnnotation
@@ -543,6 +545,7 @@ export type AnyNode =
| n.RegExpGroupCapture
| n.RegExpGroupNonCapture
| n.RegExpLiteral
+ | n.RegExpNamedBackReference
| n.RegExpNonDigitCharacter
| n.RegExpNonWhiteSpaceCharacter
| n.RegExpNonWordBoundaryCharacter

MODIFY
packages/@romejs/js-generator/generators/index.ts
packages/@romejs/js-generator/generators/index.ts
@@ -11,11 +11,9 @@ const generators: Map<string, GeneratorMethod> = new Map();
export default generators;
// EVERYTHING BELOW IS AUTOGENERATED. SEE SCRIPTS FOLDER FOR UPDATE SCRIPTS
+
import AmbiguousFlowTypeCastExpression from './temp/AmbiguousFlowTypeCastExpression';
-generators.set(
- 'AmbiguousFlowTypeCastExpression',
- AmbiguousFlowTypeCastExpression,
-);
+generators.set('AmbiguousFlowTypeCastExpression', AmbiguousFlowTypeCastExpression);
import AnyKeywordTypeAnnotation from './types/AnyKeywordTypeAnnotation';
generators.set('AnyKeywordTypeAnnotation', AnyKeywordTypeAnnotation);
@@ -42,10 +40,7 @@ import AssignmentObjectPattern from './patterns/AssignmentObjectPattern';
generators.set('AssignmentObjectPattern', AssignmentObjectPattern);
import AssignmentObjectPatternProperty from './patterns/AssignmentObjectPatternProperty';
-generators.set(
- 'AssignmentObjectPatternProperty',
- AssignmentObjectPatternProperty,
-);
+generators.set('AssignmentObjectPatternProperty', AssignmentObjectPatternProperty);
import AwaitExpression from './expressions/AwaitExpression';
generators.set('AwaitExpression', AwaitExpression);
@@ -485,6 +480,9 @@ generators.set('RegExpGroupNonCapture', RegExpGroupNonCapture);
import RegExpLiteral from './literals/RegExpLiteral';
generators.set('RegExpLiteral', RegExpLiteral);
+import RegExpNamedBackReference from './regex/RegExpNamedBackReference';
+generators.set('RegExpNamedBackReference', RegExpNamedBackReference);
+
import RegExpNonDigitCharacter from './regex/RegExpNonDigitCharacter';
generators.set('RegExpNonDigitCharacter', RegExpNonDigitCharacter);
@@ -603,10 +601,7 @@ import TSConstructorType from './typescript/TSConstructorType';
generators.set('TSConstructorType', TSConstructorType);
import TSConstructSignatureDeclaration from './typescript/TSConstructSignatureDeclaration';
-generators.set(
- 'TSConstructSignatureDeclaration',
- TSConstructSignatureDeclaration,
-);
+generators.set('TSConstructSignatureDeclaration', TSConstructSignatureDeclaration);
import TSDeclareFunction from './typescript/TSDeclareFunction';
generators.set('TSDeclareFunction', TSDeclareFunction);

ADD
packages/@romejs/js-generator/generators/regex/RegExpNamedBackReference.ts
+/**
+* Copyright (c) Facebook, Inc. and its affiliates.
+*
+* This source code is licensed under the MIT license found in the
+* LICENSE file in the root directory of this source tree.
+*/
+
+import Generator from '../../Generator';
+import {AnyNode, RegExpNamedBackReference, regExpNamedBackReference} from '@romejs/js-ast';
+
+export default function RegExpNamedBackReference(generator: Generator, node: AnyNode) {
+ node = regExpNamedBackReference.assert(node);
+ generator.append('\\k');
+ generator.append('<');
+ generator.append(node.name);
+ generator.append('>');
+}

Implement named backreference parsing