Skip to content

Commit e112f4d

Browse files
committed
No reverse mapping for syntactically known strings
1 parent 6325c1d commit e112f4d

File tree

5 files changed

+10
-25
lines changed

5 files changed

+10
-25
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45114,10 +45114,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4511445114
(isSyntacticallyString(right) || rightIsNumeric) &&
4511545115
(expr as BinaryExpression).operatorToken.kind === SyntaxKind.PlusToken
4511645116
);
45117-
case SyntaxKind.TemplateExpression:
45118-
return (expr as TemplateExpression).templateSpans.every(span => isSyntacticallyString(span.expression));
4511945117
case SyntaxKind.ParenthesizedExpression:
4512045118
return isSyntacticallyString((expr as ParenthesizedExpression).expression);
45119+
case SyntaxKind.TemplateExpression:
4512145120
case SyntaxKind.StringLiteral:
4512245121
case SyntaxKind.NoSubstitutionTemplateLiteral:
4512345122
return true;
@@ -48297,6 +48296,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4829748296
const node = getParseTreeNode(nodeIn, canHaveConstantValue);
4829848297
return node ? getConstantValue(node) : undefined;
4829948298
},
48299+
isSyntacticallyString,
4830048300
collectLinkedAliases,
4830148301
getReferencedValueDeclaration,
4830248302
getReferencedValueDeclarations,

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ export const notImplementedResolver: EmitResolver = {
11581158
isEntityNameVisible: notImplemented,
11591159
// Returns the constant value this property access resolves to: notImplemented, or 'undefined' for a non-constant
11601160
getConstantValue: notImplemented,
1161+
isSyntacticallyString: notImplemented,
11611162
getReferencedValueDeclaration: notImplemented,
11621163
getReferencedValueDeclarations: notImplemented,
11631164
getTypeReferenceSerializationKind: notImplemented,

src/compiler/transformers/ts.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,12 @@ export function transformTypeScript(context: TransformationContext) {
18731873
),
18741874
valueExpression,
18751875
);
1876-
const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ?
1876+
const isString = valueExpression.kind === SyntaxKind.StringLiteral ||
1877+
// Fix ts.transpileModule() emit: we may not have been able to determine a known string due
1878+
// to missing type information, but we know syntactically that it's a string. The checker
1879+
// ensures that only syntactically determined strings are allowed under isolatedModules.
1880+
(member.initializer && resolver.isSyntacticallyString(member.initializer));
1881+
const outerAssignment = isString ?
18771882
innerAssignment :
18781883
factory.createAssignment(
18791884
factory.createElementAccessExpression(

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5691,6 +5691,7 @@ export interface EmitResolver {
56915691
isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult;
56925692
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
56935693
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
5694+
isSyntacticallyString(node: Expression): boolean;
56945695
getReferencedValueDeclaration(reference: Identifier): Declaration | undefined;
56955696
getReferencedValueDeclarations(reference: Identifier): Declaration[] | undefined;
56965697
getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind;

tests/baselines/reference/enumWithNonLiteralStringInitializer.errors.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)