@@ -562,10 +562,17 @@ namespace ts {
562562 return emitNode && emitNode . flags || 0 ;
563563 }
564564
565- export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile , neverAsciiEscape : boolean | undefined , jsxAttributeEscape : boolean ) {
565+ export const enum GetLiteralTextFlags {
566+ None = 0 ,
567+ NeverAsciiEscape = 1 << 0 ,
568+ JsxAttributeEscape = 1 << 1 ,
569+ TerminateUnterminatedLiterals = 1 << 2 ,
570+ }
571+
572+ export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile , flags : GetLiteralTextFlags ) {
566573 // If we don't need to downlevel and we can reach the original source text using
567574 // the node's parent reference, then simply get the text as it was originally written.
568- if ( ! nodeIsSynthesized ( node ) && node . parent && ! (
575+ if ( ! nodeIsSynthesized ( node ) && node . parent && ! ( flags & GetLiteralTextFlags . TerminateUnterminatedLiterals && node . isUnterminated ) && ! (
569576 ( isNumericLiteral ( node ) && node . numericLiteralFlags & TokenFlags . ContainsSeparator ) ||
570577 isBigIntLiteral ( node )
571578 ) ) {
@@ -576,8 +583,8 @@ namespace ts {
576583 // or a (possibly escaped) quoted form of the original text if it's string-like.
577584 switch ( node . kind ) {
578585 case SyntaxKind . StringLiteral : {
579- const escapeText = jsxAttributeEscape ? escapeJsxAttributeString :
580- neverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? escapeString :
586+ const escapeText = flags & GetLiteralTextFlags . JsxAttributeEscape ? escapeJsxAttributeString :
587+ flags & GetLiteralTextFlags . NeverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? escapeString :
581588 escapeNonAsciiString ;
582589 if ( ( < StringLiteral > node ) . singleQuote ) {
583590 return "'" + escapeText ( node . text , CharacterCodes . singleQuote ) + "'" ;
@@ -592,7 +599,7 @@ namespace ts {
592599 case SyntaxKind . TemplateTail : {
593600 // If a NoSubstitutionTemplateLiteral appears to have a substitution in it, the original text
594601 // had to include a backslash: `not \${a} substitution`.
595- const escapeText = neverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? escapeString :
602+ const escapeText = flags & GetLiteralTextFlags . NeverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? escapeString :
596603 escapeNonAsciiString ;
597604
598605 const rawText = ( < TemplateLiteralLikeNode > node ) . rawText || escapeTemplateSubstitution ( escapeText ( node . text , CharacterCodes . backtick ) ) ;
@@ -610,7 +617,11 @@ namespace ts {
610617 }
611618 case SyntaxKind . NumericLiteral :
612619 case SyntaxKind . BigIntLiteral :
620+ return node . text ;
613621 case SyntaxKind . RegularExpressionLiteral :
622+ if ( flags & GetLiteralTextFlags . TerminateUnterminatedLiterals && node . isUnterminated ) {
623+ return node . text + ( node . text . charCodeAt ( node . text . length - 1 ) === CharacterCodes . backslash ? " /" : "/" ) ;
624+ }
614625 return node . text ;
615626 }
616627
@@ -1858,7 +1869,7 @@ namespace ts {
18581869
18591870 export function getExternalModuleRequireArgument ( node : Node ) {
18601871 return isRequireVariableDeclaration ( node , /*requireStringLiteralLikeArgument*/ true )
1861- && ( getLeftmostPropertyAccessExpression ( node . initializer ) as CallExpression ) . arguments [ 0 ] as StringLiteral ;
1872+ && ( getLeftmostAccessExpression ( node . initializer ) as CallExpression ) . arguments [ 0 ] as StringLiteral ;
18621873 }
18631874
18641875 export function isInternalModuleImportEqualsDeclaration ( node : Node ) : node is ImportEqualsDeclaration {
@@ -1929,7 +1940,7 @@ namespace ts {
19291940 export function isRequireVariableDeclaration ( node : Node , requireStringLiteralLikeArgument : boolean ) : node is VariableDeclaration ;
19301941 export function isRequireVariableDeclaration ( node : Node , requireStringLiteralLikeArgument : boolean ) : node is VariableDeclaration {
19311942 node = getRootDeclaration ( node ) ;
1932- return isVariableDeclaration ( node ) && ! ! node . initializer && isRequireCall ( getLeftmostPropertyAccessExpression ( node . initializer ) , requireStringLiteralLikeArgument ) ;
1943+ return isVariableDeclaration ( node ) && ! ! node . initializer && isRequireCall ( getLeftmostAccessExpression ( node . initializer ) , requireStringLiteralLikeArgument ) ;
19331944 }
19341945
19351946 export function isRequireVariableStatement ( node : Node , requireStringLiteralLikeArgument = true ) : node is RequireVariableStatement {
@@ -5452,8 +5463,8 @@ namespace ts {
54525463 return node . kind === SyntaxKind . NamedImports || node . kind === SyntaxKind . NamedExports ;
54535464 }
54545465
5455- export function getLeftmostPropertyAccessExpression ( expr : Expression ) : Expression {
5456- while ( isPropertyAccessExpression ( expr ) ) {
5466+ export function getLeftmostAccessExpression ( expr : Expression ) : Expression {
5467+ while ( isAccessExpression ( expr ) ) {
54575468 expr = expr . expression ;
54585469 }
54595470 return expr ;
@@ -5922,6 +5933,10 @@ namespace ts {
59225933 return compilerOptions [ flag ] === undefined ? ! ! compilerOptions . strict : ! ! compilerOptions [ flag ] ;
59235934 }
59245935
5936+ export function getAllowJSCompilerOption ( compilerOptions : CompilerOptions ) : boolean {
5937+ return compilerOptions . allowJs === undefined ? ! ! compilerOptions . checkJs : compilerOptions . allowJs ;
5938+ }
5939+
59255940 export function compilerOptionsAffectSemanticDiagnostics ( newOptions : CompilerOptions , oldOptions : CompilerOptions ) : boolean {
59265941 return oldOptions !== newOptions &&
59275942 semanticDiagnosticsOptionDeclarations . some ( option => ! isJsonEqual ( getCompilerOptionValue ( oldOptions , option ) , getCompilerOptionValue ( newOptions , option ) ) ) ;
@@ -6375,7 +6390,7 @@ namespace ts {
63756390 export function getSupportedExtensions ( options ?: CompilerOptions ) : readonly Extension [ ] ;
63766391 export function getSupportedExtensions ( options ?: CompilerOptions , extraFileExtensions ?: readonly FileExtensionInfo [ ] ) : readonly string [ ] ;
63776392 export function getSupportedExtensions ( options ?: CompilerOptions , extraFileExtensions ?: readonly FileExtensionInfo [ ] ) : readonly string [ ] {
6378- const needJsExtensions = options && options . allowJs ;
6393+ const needJsExtensions = options && getAllowJSCompilerOption ( options ) ;
63796394
63806395 if ( ! extraFileExtensions || extraFileExtensions . length === 0 ) {
63816396 return needJsExtensions ? allSupportedExtensions : supportedTSExtensions ;
0 commit comments