@@ -322,21 +322,11 @@ namespace ts {
322322 return getSourceTextOfNodeFromSourceFile ( getSourceFileOfNode ( node ) , node , includeTrivia ) ;
323323 }
324324
325- export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile , languageVersion : ScriptTarget ) {
326- // Any template literal or string literal with an extended escape
327- // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal.
328- if ( languageVersion < ScriptTarget . ES2015 && ( isTemplateLiteralKind ( node . kind ) || node . hasExtendedUnicodeEscape ) ) {
329- return getQuotedEscapedLiteralText ( '"' , node . text , '"' ) ;
330- }
331-
325+ export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile ) {
332326 // If we don't need to downlevel and we can reach the original source text using
333327 // the node's parent reference, then simply get the text as it was originally written.
334328 if ( ! nodeIsSynthesized ( node ) && node . parent ) {
335- const text = getSourceTextOfNodeFromSourceFile ( sourceFile , node ) ;
336- if ( languageVersion < ScriptTarget . ES2015 && isBinaryOrOctalIntegerLiteral ( node , text ) ) {
337- return node . text ;
338- }
339- return text ;
329+ return getSourceTextOfNodeFromSourceFile ( sourceFile , node ) ;
340330 }
341331
342332 // If we can't reach the original source text, use the canonical form if it's a number,
@@ -359,55 +349,6 @@ namespace ts {
359349 Debug . fail ( `Literal kind '${ node . kind } ' not accounted for.` ) ;
360350 }
361351
362- export function isBinaryOrOctalIntegerLiteral ( node : LiteralLikeNode , text : string ) {
363- return node . kind === SyntaxKind . NumericLiteral
364- && ( getNumericLiteralFlags ( text , /*hint*/ NumericLiteralFlags . BinaryOrOctal ) & NumericLiteralFlags . BinaryOrOctal ) !== 0 ;
365- }
366-
367- export const enum NumericLiteralFlags {
368- None = 0 ,
369- Hexadecimal = 1 << 0 ,
370- Binary = 1 << 1 ,
371- Octal = 1 << 2 ,
372- Scientific = 1 << 3 ,
373-
374- BinaryOrOctal = Binary | Octal ,
375- BinaryOrOctalOrHexadecimal = BinaryOrOctal | Hexadecimal ,
376- All = Hexadecimal | Binary | Octal | Scientific ,
377- }
378-
379- /**
380- * Scans a numeric literal string to determine the form of the number.
381- * @param text Numeric literal text
382- * @param hint If `Scientific` or `All` is specified, performs a more expensive check to scan for scientific notation.
383- */
384- export function getNumericLiteralFlags ( text : string , hint ?: NumericLiteralFlags ) {
385- if ( text . length > 1 ) {
386- switch ( text . charCodeAt ( 1 ) ) {
387- case CharacterCodes . b :
388- case CharacterCodes . B :
389- return NumericLiteralFlags . Binary ;
390- case CharacterCodes . o :
391- case CharacterCodes . O :
392- return NumericLiteralFlags . Octal ;
393- case CharacterCodes . x :
394- case CharacterCodes . X :
395- return NumericLiteralFlags . Hexadecimal ;
396- }
397-
398- if ( hint & NumericLiteralFlags . Scientific ) {
399- for ( let i = text . length - 1 ; i >= 0 ; i -- ) {
400- switch ( text . charCodeAt ( i ) ) {
401- case CharacterCodes . e :
402- case CharacterCodes . E :
403- return NumericLiteralFlags . Scientific ;
404- }
405- }
406- }
407- }
408- return NumericLiteralFlags . None ;
409- }
410-
411352 function getQuotedEscapedLiteralText ( leftQuote : string , text : string , rightQuote : string ) {
412353 return leftQuote + escapeNonAsciiCharacters ( escapeString ( text ) ) + rightQuote ;
413354 }
@@ -2027,6 +1968,10 @@ namespace ts {
20271968 return false ;
20281969 }
20291970
1971+ export function isNumericLiteral ( node : Node ) : node is NumericLiteral {
1972+ return node . kind === SyntaxKind . NumericLiteral ;
1973+ }
1974+
20301975 export function isStringOrNumericLiteral ( node : Node ) : node is StringLiteral | NumericLiteral {
20311976 const kind = node . kind ;
20321977 return kind === SyntaxKind . StringLiteral
0 commit comments