Skip to content

Commit

Permalink
No reverse mapping for syntactically known strings
Browse files Browse the repository at this point in the history
  • Loading branch information
frigus02 committed Jan 25, 2024
1 parent 6325c1d commit e112f4d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -45114,10 +45114,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
(isSyntacticallyString(right) || rightIsNumeric) &&
(expr as BinaryExpression).operatorToken.kind === SyntaxKind.PlusToken
);
case SyntaxKind.TemplateExpression:
return (expr as TemplateExpression).templateSpans.every(span => isSyntacticallyString(span.expression));
case SyntaxKind.ParenthesizedExpression:
return isSyntacticallyString((expr as ParenthesizedExpression).expression);
case SyntaxKind.TemplateExpression:
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
return true;
Expand Down Expand Up @@ -48297,6 +48296,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const node = getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
},
isSyntacticallyString,
collectLinkedAliases,
getReferencedValueDeclaration,
getReferencedValueDeclarations,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/emitter.ts
Expand Up @@ -1158,6 +1158,7 @@ export const notImplementedResolver: EmitResolver = {
isEntityNameVisible: notImplemented,
// Returns the constant value this property access resolves to: notImplemented, or 'undefined' for a non-constant
getConstantValue: notImplemented,
isSyntacticallyString: notImplemented,
getReferencedValueDeclaration: notImplemented,
getReferencedValueDeclarations: notImplemented,
getTypeReferenceSerializationKind: notImplemented,
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/transformers/ts.ts
Expand Up @@ -1873,7 +1873,12 @@ export function transformTypeScript(context: TransformationContext) {
),
valueExpression,
);
const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ?
const isString = valueExpression.kind === SyntaxKind.StringLiteral ||
// Fix ts.transpileModule() emit: we may not have been able to determine a known string due
// to missing type information, but we know syntactically that it's a string. The checker
// ensures that only syntactically determined strings are allowed under isolatedModules.
(member.initializer && resolver.isSyntacticallyString(member.initializer));
const outerAssignment = isString ?
innerAssignment :
factory.createAssignment(
factory.createElementAccessExpression(
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Expand Up @@ -5691,6 +5691,7 @@ export interface EmitResolver {
isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult;
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
isSyntacticallyString(node: Expression): boolean;
getReferencedValueDeclaration(reference: Identifier): Declaration | undefined;
getReferencedValueDeclarations(reference: Identifier): Declaration[] | undefined;
getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind;
Expand Down

This file was deleted.

0 comments on commit e112f4d

Please sign in to comment.