Skip to content
Permalink
Browse files
Allow Unicode extended escapes in ES5 and earlier (#50918)
* Remove language version check for extended escapes.

* Accepted baselines.

* Record whether nodes have extended Unicode escapes. Replace them in the es2015 transform.

* Accepted baselines.

* Move file to better-reflect generality of tests.

* Added tests for variables at the top level.

* Accepted baselines.

* Added test for extended astral character.

* Accepted baseline.

* Enable sourcemaps in tests.

* Accepted baselines.

* Call `setOriginalNode` on identifiers with extended escapes.
  • Loading branch information
DanielRosenwasser committed Sep 30, 2022
1 parent 58bae8d commit 0d0a79371471d627ae298a145f8009b05cbccb72
Show file tree
Hide file tree
Showing 36 changed files with 7,010 additions and 497 deletions.
@@ -874,7 +874,7 @@ namespace ts {
}

// @api
function createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind): Identifier {
function createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier {
const node = createBaseIdentifier(text, originalKeywordKind);
if (typeArguments) {
// NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations
@@ -883,6 +883,10 @@ namespace ts {
if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) {
node.transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait;
}
if (hasExtendedUnicodeEscape) {
node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape;
node.transformFlags |= TransformFlags.ContainsES2015;
}
return node;
}

@@ -2187,8 +2187,9 @@ namespace ts {
// Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker
const originalKeywordKind = token();
const text = internIdentifier(scanner.getTokenValue());
const hasExtendedUnicodeEscape = scanner.hasExtendedUnicodeEscape();
nextTokenWithoutCheck();
return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind), pos);
return finishNode(factory.createIdentifier(text, /*typeArguments*/ undefined, originalKeywordKind, hasExtendedUnicodeEscape), pos);
}

if (token() === SyntaxKind.PrivateIdentifier) {
@@ -1486,7 +1486,7 @@ namespace ts {


function peekExtendedUnicodeEscape(): number {
if (languageVersion >= ScriptTarget.ES2015 && codePointAt(text, pos + 1) === CharacterCodes.u && codePointAt(text, pos + 2) === CharacterCodes.openBrace) {
if (codePointAt(text, pos + 1) === CharacterCodes.u && codePointAt(text, pos + 2) === CharacterCodes.openBrace) {
const start = pos;
pos += 3;
const escapedValueString = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
@@ -643,11 +643,16 @@ namespace ts {
}

function visitIdentifier(node: Identifier): Identifier {
if (!convertedLoopState) {
return node;
if (convertedLoopState) {
if (resolver.isArgumentsLocalBinding(node)) {
return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments"));
}
}
if (resolver.isArgumentsLocalBinding(node)) {
return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = factory.createUniqueName("arguments"));
if (node.hasExtendedUnicodeEscape) {
return setOriginalNode(setTextRange(
factory.createIdentifier(unescapeLeadingUnderscores(node.escapedText)),
node
), node);
}
return node;
}
@@ -1427,6 +1427,7 @@ namespace ts {
isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace
/*@internal*/ typeArguments?: NodeArray<TypeNode | TypeParameterDeclaration>; // Only defined on synthesized nodes. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help.
/*@internal*/ jsdocDotPos?: number; // Identifier occurs in JSDoc-style generic: Id.<T>
/*@internal*/ hasExtendedUnicodeEscape?: boolean;
}

// Transient identifier node (marked by id === -1)
@@ -7653,7 +7654,7 @@ namespace ts {
//

createIdentifier(text: string): Identifier;
/* @internal */ createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures
/* @internal */ createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind, hasExtendedUnicodeEscape?: boolean): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures
/* @internal */ updateIdentifier(node: Identifier, typeArguments: NodeArray<TypeNode | TypeParameterDeclaration> | undefined): Identifier;

/**

0 comments on commit 0d0a793

Please sign in to comment.