2015-06-12 18:01:48 +02:00
namespace ts {
2017-01-30 21:27:24 +01:00
const brackets = createBracketsMap ( ) ;
2016-09-27 23:02:10 +02:00
2019-02-07 19:14:38 +01:00
/*@internal*/
2019-02-21 20:28:52 +01:00
export function isBuildInfoFile ( file : string ) {
2019-02-28 01:15:09 +01:00
return fileExtensionIs ( file , Extension . TsBuildInfo ) ;
2019-02-07 19:14:38 +01:00
}
2017-05-27 00:37:41 +02:00
/*@internal*/
/ * *
* Iterates over the source files that are expected to have an emit output .
*
* @param host An EmitHost .
* @param action The action to execute .
* @param sourceFilesOrTargetSourceFile
* If an array , the full list of source files to emit .
* Else , calls ` getSourceFilesToEmit ` with the ( optional ) target source file to determine the list of source files to emit .
* /
2018-01-11 20:52:46 +01:00
export function forEachEmittedFile < T > (
2019-02-05 21:30:20 +01:00
host : EmitHost , action : ( emitFileNames : EmitFileNames , sourceFileOrBundle : SourceFile | Bundle | undefined ) = > T ,
2019-08-08 20:30:18 +02:00
sourceFilesOrTargetSourceFile? : readonly SourceFile [ ] | SourceFile ,
2019-09-10 01:16:57 +02:00
forceDtsEmit = false ,
2019-02-06 04:35:08 +01:00
onlyBuildInfo? : boolean ,
includeBuildInfo? : boolean ) {
2019-11-27 22:47:19 +01:00
const sourceFiles = isArray ( sourceFilesOrTargetSourceFile ) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit ( host , sourceFilesOrTargetSourceFile , forceDtsEmit ) ;
2017-05-27 00:37:41 +02:00
const options = host . getCompilerOptions ( ) ;
2020-06-02 20:49:21 +02:00
if ( outFile ( options ) ) {
2019-02-01 23:46:58 +01:00
const prepends = host . getPrependNodes ( ) ;
if ( sourceFiles . length || prepends . length ) {
2020-06-17 01:55:03 +02:00
const bundle = factory . createBundle ( sourceFiles , prepends ) ;
2019-09-10 01:16:57 +02:00
const result = action ( getOutputPathsFor ( bundle , host , forceDtsEmit ) , bundle ) ;
2018-01-11 20:52:46 +01:00
if ( result ) {
return result ;
}
2017-05-27 00:37:41 +02:00
}
}
else {
2019-02-06 04:35:08 +01:00
if ( ! onlyBuildInfo ) {
for ( const sourceFile of sourceFiles ) {
2019-09-10 01:16:57 +02:00
const result = action ( getOutputPathsFor ( sourceFile , host , forceDtsEmit ) , sourceFile ) ;
2019-02-06 04:35:08 +01:00
if ( result ) {
return result ;
}
2018-01-11 20:52:46 +01:00
}
2017-05-27 00:37:41 +02:00
}
2019-02-06 04:35:08 +01:00
if ( includeBuildInfo ) {
2020-06-02 20:49:21 +02:00
const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( options ) ;
2019-02-08 01:13:55 +01:00
if ( buildInfoPath ) return action ( { buildInfoPath } , /*sourceFileOrBundle*/ undefined ) ;
2019-02-06 04:35:08 +01:00
}
2017-05-27 00:37:41 +02:00
}
}
2019-09-18 23:02:41 +02:00
export function getTsBuildInfoEmitOutputFilePath ( options : CompilerOptions ) {
2019-02-28 01:15:09 +01:00
const configFile = options . configFilePath ;
2019-03-25 20:37:55 +01:00
if ( ! isIncrementalCompilation ( options ) ) return undefined ;
2019-03-01 18:58:16 +01:00
if ( options . tsBuildInfoFile ) return options . tsBuildInfoFile ;
2020-06-02 20:49:21 +02:00
const outPath = outFile ( options ) ;
2019-02-28 01:15:09 +01:00
let buildInfoExtensionLess : string ;
if ( outPath ) {
buildInfoExtensionLess = removeFileExtension ( outPath ) ;
}
else {
2019-03-25 20:37:55 +01:00
if ( ! configFile ) return undefined ;
2019-02-28 01:15:09 +01:00
const configFileExtensionLess = removeFileExtension ( configFile ) ;
buildInfoExtensionLess = options . outDir ?
options . rootDir ?
resolvePath ( options . outDir , getRelativePathFromDirectory ( options . rootDir , configFileExtensionLess , /*ignoreCase*/ true ) ) :
combinePaths ( options . outDir , getBaseFileName ( configFileExtensionLess ) ) :
configFileExtensionLess ;
}
return buildInfoExtensionLess + Extension . TsBuildInfo ;
2019-01-31 02:48:34 +01:00
}
2019-01-24 21:40:52 +01:00
/*@internal*/
2019-02-28 01:15:09 +01:00
export function getOutputPathsForBundle ( options : CompilerOptions , forceDtsPaths : boolean ) : EmitFileNames {
2020-06-02 20:49:21 +02:00
const outPath = outFile ( options ) ! ;
2019-01-24 21:40:52 +01:00
const jsFilePath = options . emitDeclarationOnly ? undefined : outPath ;
const sourceMapFilePath = jsFilePath && getSourceMapFilePath ( jsFilePath , options ) ;
const declarationFilePath = ( forceDtsPaths || getEmitDeclarations ( options ) ) ? removeFileExtension ( outPath ) + Extension.Dts : undefined ;
const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
2019-09-18 23:02:41 +02:00
const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( options ) ;
2019-01-30 19:01:49 +01:00
return { jsFilePath , sourceMapFilePath , declarationFilePath , declarationMapPath , buildInfoPath } ;
2019-01-24 21:40:52 +01:00
}
2018-03-16 06:23:10 +01:00
/*@internal*/
2018-05-22 23:46:57 +02:00
export function getOutputPathsFor ( sourceFile : SourceFile | Bundle , host : EmitHost , forceDtsPaths : boolean ) : EmitFileNames {
2018-03-16 06:23:10 +01:00
const options = host . getCompilerOptions ( ) ;
if ( sourceFile . kind === SyntaxKind . Bundle ) {
2019-02-28 01:15:09 +01:00
return getOutputPathsForBundle ( options , forceDtsPaths ) ;
2018-03-16 06:23:10 +01:00
}
else {
2018-10-11 19:09:47 +02:00
const ownOutputFilePath = getOwnEmitOutputFilePath ( sourceFile . fileName , host , getOutputExtension ( sourceFile , options ) ) ;
2020-01-08 18:54:32 +01:00
const isJsonFile = isJsonSourceFile ( sourceFile ) ;
2018-10-11 19:09:47 +02:00
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
2020-01-08 18:54:32 +01:00
const isJsonEmittedToSameLocation = isJsonFile &&
2018-10-11 18:31:04 +02:00
comparePaths ( sourceFile . fileName , ownOutputFilePath , host . getCurrentDirectory ( ) , ! host . useCaseSensitiveFileNames ( ) ) === Comparison . EqualTo ;
const jsFilePath = options . emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath ;
2018-10-11 19:09:47 +02:00
const sourceMapFilePath = ! jsFilePath || isJsonSourceFile ( sourceFile ) ? undefined : getSourceMapFilePath ( jsFilePath , options ) ;
2020-01-08 18:54:32 +01:00
const declarationFilePath = ( forceDtsPaths || ( getEmitDeclarations ( options ) && ! isJsonFile ) ) ? getDeclarationEmitOutputFilePath ( sourceFile . fileName , host ) : undefined ;
2018-10-11 19:09:47 +02:00
const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
2019-01-30 19:01:49 +01:00
return { jsFilePath , sourceMapFilePath , declarationFilePath , declarationMapPath , buildInfoPath : undefined } ;
2018-03-16 06:23:10 +01:00
}
}
2017-05-27 00:37:41 +02:00
function getSourceMapFilePath ( jsFilePath : string , options : CompilerOptions ) {
2018-03-26 21:15:34 +02:00
return ( options . sourceMap && ! options . inlineSourceMap ) ? jsFilePath + ".map" : undefined ;
2017-05-27 00:37:41 +02:00
}
// JavaScript files are always LanguageVariant.JSX, as JSX syntax is allowed in .js files also.
// So for JavaScript files, '.jsx' is only emitted if the input was '.jsx', and JsxEmit.Preserve.
// For TypeScript, the only time to emit with a '.jsx' extension, is on JSX input, and JsxEmit.Preserve
2017-11-10 01:01:33 +01:00
/* @internal */
export function getOutputExtension ( sourceFile : SourceFile , options : CompilerOptions ) : Extension {
2017-01-17 22:51:00 +01:00
if ( isJsonSourceFile ( sourceFile ) ) {
return Extension . Json ;
}
2017-05-27 00:37:41 +02:00
if ( options . jsx === JsxEmit . Preserve ) {
2018-09-12 19:44:46 +02:00
if ( isSourceFileJS ( sourceFile ) ) {
2017-06-15 18:59:37 +02:00
if ( fileExtensionIs ( sourceFile . fileName , Extension . Jsx ) ) {
return Extension . Jsx ;
2017-05-27 00:37:41 +02:00
}
}
else if ( sourceFile . languageVariant === LanguageVariant . JSX ) {
// TypeScript source file preserving JSX syntax
2017-06-15 18:59:37 +02:00
return Extension . Jsx ;
2017-05-27 00:37:41 +02:00
}
}
2017-06-15 18:59:37 +02:00
return Extension . Js ;
2017-05-27 00:37:41 +02:00
}
2020-12-07 20:53:22 +01:00
function getOutputPathWithoutChangingExt ( inputFileName : string , configFile : ParsedCommandLine , ignoreCase : boolean , outputDir : string | undefined , getCommonSourceDirectory ? : ( ) = > string ) {
2019-03-14 22:15:06 +01:00
return outputDir ?
resolvePath (
outputDir ,
2020-12-07 20:53:22 +01:00
getRelativePathFromDirectory ( getCommonSourceDirectory ? getCommonSourceDirectory ( ) : getCommonSourceDirectoryOfConfig ( configFile , ignoreCase ) , inputFileName , ignoreCase )
2019-03-14 22:15:06 +01:00
) :
inputFileName ;
}
2019-03-13 17:58:26 +01:00
/* @internal */
2020-12-07 20:53:22 +01:00
export function getOutputDeclarationFileName ( inputFileName : string , configFile : ParsedCommandLine , ignoreCase : boolean , getCommonSourceDirectory ? : ( ) = > string ) {
2020-01-08 18:54:32 +01:00
Debug . assert ( ! fileExtensionIs ( inputFileName , Extension . Dts ) && ! fileExtensionIs ( inputFileName , Extension . Json ) ) ;
2019-03-14 22:15:06 +01:00
return changeExtension (
2020-12-07 20:53:22 +01:00
getOutputPathWithoutChangingExt ( inputFileName , configFile , ignoreCase , configFile . options . declarationDir || configFile . options . outDir , getCommonSourceDirectory ) ,
2019-03-14 22:15:06 +01:00
Extension . Dts
) ;
2019-03-13 17:58:26 +01:00
}
2020-12-07 20:53:22 +01:00
function getOutputJSFileName ( inputFileName : string , configFile : ParsedCommandLine , ignoreCase : boolean , getCommonSourceDirectory ? : ( ) = > string ) {
2019-08-31 01:33:44 +02:00
if ( configFile . options . emitDeclarationOnly ) return undefined ;
2019-03-13 17:58:26 +01:00
const isJsonFile = fileExtensionIs ( inputFileName , Extension . Json ) ;
2019-03-14 22:15:06 +01:00
const outputFileName = changeExtension (
2020-12-07 20:53:22 +01:00
getOutputPathWithoutChangingExt ( inputFileName , configFile , ignoreCase , configFile . options . outDir , getCommonSourceDirectory ) ,
2019-03-14 22:15:06 +01:00
isJsonFile ?
Extension . Json :
2020-12-07 20:53:22 +01:00
configFile . options . jsx === JsxEmit . Preserve && ( fileExtensionIs ( inputFileName , Extension . Tsx ) || fileExtensionIs ( inputFileName , Extension . Jsx ) ) ?
2019-03-14 22:15:06 +01:00
Extension . Jsx :
Extension . Js
) ;
2020-02-25 03:20:58 +01:00
return ! isJsonFile || comparePaths ( inputFileName , outputFileName , Debug . checkDefined ( configFile . options . configFilePath ) , ignoreCase ) !== Comparison . EqualTo ?
2019-03-13 17:58:26 +01:00
outputFileName :
undefined ;
}
2019-09-18 23:02:41 +02:00
function createAddOutput() {
let outputs : string [ ] | undefined ;
return { addOutput , getOutputs } ;
function addOutput ( path : string | undefined ) {
if ( path ) {
( outputs || ( outputs = [ ] ) ) . push ( path ) ;
}
}
function getOutputs ( ) : readonly string [ ] {
return outputs || emptyArray ;
}
}
function getSingleOutputFileNames ( configFile : ParsedCommandLine , addOutput : ReturnType < typeof createAddOutput > [ "addOutput" ] ) {
const { jsFilePath , sourceMapFilePath , declarationFilePath , declarationMapPath , buildInfoPath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
addOutput ( jsFilePath ) ;
addOutput ( sourceMapFilePath ) ;
addOutput ( declarationFilePath ) ;
addOutput ( declarationMapPath ) ;
addOutput ( buildInfoPath ) ;
}
2020-12-07 20:53:22 +01:00
function getOwnOutputFileNames ( configFile : ParsedCommandLine , inputFileName : string , ignoreCase : boolean , addOutput : ReturnType < typeof createAddOutput > [ "addOutput" ] , getCommonSourceDirectory ? : ( ) = > string ) {
2019-09-18 23:02:41 +02:00
if ( fileExtensionIs ( inputFileName , Extension . Dts ) ) return ;
2020-12-07 20:53:22 +01:00
const js = getOutputJSFileName ( inputFileName , configFile , ignoreCase , getCommonSourceDirectory ) ;
2019-09-18 23:02:41 +02:00
addOutput ( js ) ;
if ( fileExtensionIs ( inputFileName , Extension . Json ) ) return ;
if ( js && configFile . options . sourceMap ) {
addOutput ( ` ${ js } .map ` ) ;
}
Allow `allowJs` and `declaration` to be used together (#32372)
* Allow allowJs and declaration to be used together
This intorduces a new symbol-based declaration emitter - currently this
is only used for JSON and JavaScript, as the output is likely worse than
what the other declaration emitter is capable of. In addition, it is
still incomplete - it does not yet support serializaing namespaces.
* Add tests for various import/export forms, add notes on export as namespace and fix export * from
* Tests & fixes for computed names
* Add test with current @enum tag behavior
* fix declaration emit for jsdoc @enum tags
* Small adjustments to base class serialization to fix bugs in it
* Guard against type/type parameter confusion when using typeParameterToName a bit
* Integrate feedback from PR
* Fix issue with export= declarations visibility calculation and type declaration emit that impacted all forms of declaration emit
* Only make one merged getCommonJsExportEquals symbol for a symbol
* Support preserving type reference directives in js declarations
* Skip declare mdoifiers for namespace members in ambient contexts
* FAKE ALIASES AND NAMESPACES EVERYWHERE
* Dont do namespace sugar when type members contain keyword names
* Fix json source file export modifier under new output
* Such clean nested aliasing, very wow
* Fix lint
* Add visibility errors, reuse type nodes where possible
* Suppoer having correctly named import types in bundled js declaration emit & adjust binding to allow namespaces with aliases to merge when the aliases look to be type-only
* Better support for module.exports = class expression
* Fix discovered crash bug
* Allow export assigned class expressions to be reachable symbols from external declarations
* Add missing semicolon
* Support @enum tag post-merge
* preserve comments on signatures and declarations where possible
* Basic support for js classy functions
* Add example we should do better with
* Prototype assignments make things a bit wonky, but the example from the PR seems OK
* Make a ton of changes to support the new way js classes are bound
* Remove some old comments, fix import and export default names
* Fix bug in object define handling and add tests for object define property declaration emit
* Fix organization nits from PR comments
* Preserve comments from jsdoc declarations on properties and js declaration type aliases
* Merge export declarations with identical specifiers
* Remove completed TODO comment
* Split lint
* Remove now-unused function
* PR feedback
* Add some project references tests, remove some checks from project refs codepaths that are now invalid
* Update project references tests again
* Merge and update project references tests
* Rename case
* Update test to include declaration output
* Remove yet another project refernces redirect extension check
* Update comment
* Add additional import ref to test
* Add shorthand prop to test
* Fix comment text
* Extract var to temp
* Simplify function and add whitespace
* Update project refs test to use incremental edit entry
* Stylistic refactors in the symbol serializer
* Another round of PR feedback, mostly style, small bugfix with constructors, and test showing bug in export assigned class expression name shadowing
* Use x instead of index
2019-09-26 23:27:16 +02:00
if ( getEmitDeclarations ( configFile . options ) ) {
2020-12-07 20:53:22 +01:00
const dts = getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase , getCommonSourceDirectory ) ;
2019-09-18 23:02:41 +02:00
addOutput ( dts ) ;
if ( configFile . options . declarationMap ) {
addOutput ( ` ${ dts } .map ` ) ;
}
}
}
2020-12-07 20:53:22 +01:00
/*@internal*/
export function getCommonSourceDirectory (
options : CompilerOptions ,
emittedFiles : ( ) = > readonly string [ ] ,
currentDirectory : string ,
getCanonicalFileName : GetCanonicalFileName ,
checkSourceFilesBelongToPath ? : ( commonSourceDirectory : string ) = > void
) : string {
let commonSourceDirectory ;
if ( options . rootDir ) {
// If a rootDir is specified use it as the commonSourceDirectory
commonSourceDirectory = getNormalizedAbsolutePath ( options . rootDir , currentDirectory ) ;
checkSourceFilesBelongToPath ? . ( options . rootDir ) ;
}
else if ( options . composite && options . configFilePath ) {
// Project compilations never infer their root from the input source paths
commonSourceDirectory = getDirectoryPath ( normalizeSlashes ( options . configFilePath ) ) ;
checkSourceFilesBelongToPath ? . ( commonSourceDirectory ) ;
}
else {
commonSourceDirectory = computeCommonSourceDirectoryOfFilenames ( emittedFiles ( ) , currentDirectory , getCanonicalFileName ) ;
}
if ( commonSourceDirectory && commonSourceDirectory [ commonSourceDirectory . length - 1 ] !== directorySeparator ) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator ;
}
return commonSourceDirectory ;
}
/*@internal*/
export function getCommonSourceDirectoryOfConfig ( { options , fileNames } : ParsedCommandLine , ignoreCase : boolean ) : string {
return getCommonSourceDirectory (
options ,
( ) = > filter ( fileNames , file = > ! ( options . noEmitForJsFiles && fileExtensionIsOneOf ( file , supportedJSExtensions ) ) && ! fileExtensionIs ( file , Extension . Dts ) ) ,
getDirectoryPath ( normalizeSlashes ( Debug . checkDefined ( options . configFilePath ) ) ) ,
createGetCanonicalFileName ( ! ignoreCase )
) ;
}
2019-03-13 17:58:26 +01:00
/*@internal*/
2019-08-08 20:30:18 +02:00
export function getAllProjectOutputs ( configFile : ParsedCommandLine , ignoreCase : boolean ) : readonly string [ ] {
2019-09-18 23:02:41 +02:00
const { addOutput , getOutputs } = createAddOutput ( ) ;
2020-06-02 20:49:21 +02:00
if ( outFile ( configFile . options ) ) {
2019-09-18 23:02:41 +02:00
getSingleOutputFileNames ( configFile , addOutput ) ;
2019-03-13 17:58:26 +01:00
}
else {
2020-12-07 20:53:22 +01:00
const getCommonSourceDirectory = memoize ( ( ) = > getCommonSourceDirectoryOfConfig ( configFile , ignoreCase ) ) ;
2019-03-13 17:58:26 +01:00
for ( const inputFileName of configFile . fileNames ) {
2020-12-07 20:53:22 +01:00
getOwnOutputFileNames ( configFile , inputFileName , ignoreCase , addOutput , getCommonSourceDirectory ) ;
2019-03-13 17:58:26 +01:00
}
2019-09-18 23:02:41 +02:00
addOutput ( getTsBuildInfoEmitOutputFilePath ( configFile . options ) ) ;
2019-03-13 17:58:26 +01:00
}
2019-09-18 23:02:41 +02:00
return getOutputs ( ) ;
}
export function getOutputFileNames ( commandLine : ParsedCommandLine , inputFileName : string , ignoreCase : boolean ) : readonly string [ ] {
inputFileName = normalizePath ( inputFileName ) ;
Debug . assert ( contains ( commandLine . fileNames , inputFileName ) , ` Expected fileName to be present in command line ` ) ;
const { addOutput , getOutputs } = createAddOutput ( ) ;
2020-06-02 20:49:21 +02:00
if ( outFile ( commandLine . options ) ) {
2019-09-18 23:02:41 +02:00
getSingleOutputFileNames ( commandLine , addOutput ) ;
}
else {
getOwnOutputFileNames ( commandLine , inputFileName , ignoreCase , addOutput ) ;
2019-03-13 17:58:26 +01:00
}
2019-09-18 23:02:41 +02:00
return getOutputs ( ) ;
2019-03-13 17:58:26 +01:00
}
/*@internal*/
export function getFirstProjectOutput ( configFile : ParsedCommandLine , ignoreCase : boolean ) : string {
2020-06-02 20:49:21 +02:00
if ( outFile ( configFile . options ) ) {
2019-03-13 17:58:26 +01:00
const { jsFilePath } = getOutputPathsForBundle ( configFile . options , /*forceDtsPaths*/ false ) ;
2020-02-25 03:20:58 +01:00
return Debug . checkDefined ( jsFilePath , ` project ${ configFile . options . configFilePath } expected to have at least one output ` ) ;
2019-03-13 17:58:26 +01:00
}
2020-12-07 20:53:22 +01:00
const getCommonSourceDirectory = memoize ( ( ) = > getCommonSourceDirectoryOfConfig ( configFile , ignoreCase ) ) ;
2019-03-13 17:58:26 +01:00
for ( const inputFileName of configFile . fileNames ) {
if ( fileExtensionIs ( inputFileName , Extension . Dts ) ) continue ;
2020-12-07 20:53:22 +01:00
const jsFilePath = getOutputJSFileName ( inputFileName , configFile , ignoreCase , getCommonSourceDirectory ) ;
2019-03-13 17:58:26 +01:00
if ( jsFilePath ) return jsFilePath ;
2019-08-31 01:33:44 +02:00
if ( fileExtensionIs ( inputFileName , Extension . Json ) ) continue ;
Allow `allowJs` and `declaration` to be used together (#32372)
* Allow allowJs and declaration to be used together
This intorduces a new symbol-based declaration emitter - currently this
is only used for JSON and JavaScript, as the output is likely worse than
what the other declaration emitter is capable of. In addition, it is
still incomplete - it does not yet support serializaing namespaces.
* Add tests for various import/export forms, add notes on export as namespace and fix export * from
* Tests & fixes for computed names
* Add test with current @enum tag behavior
* fix declaration emit for jsdoc @enum tags
* Small adjustments to base class serialization to fix bugs in it
* Guard against type/type parameter confusion when using typeParameterToName a bit
* Integrate feedback from PR
* Fix issue with export= declarations visibility calculation and type declaration emit that impacted all forms of declaration emit
* Only make one merged getCommonJsExportEquals symbol for a symbol
* Support preserving type reference directives in js declarations
* Skip declare mdoifiers for namespace members in ambient contexts
* FAKE ALIASES AND NAMESPACES EVERYWHERE
* Dont do namespace sugar when type members contain keyword names
* Fix json source file export modifier under new output
* Such clean nested aliasing, very wow
* Fix lint
* Add visibility errors, reuse type nodes where possible
* Suppoer having correctly named import types in bundled js declaration emit & adjust binding to allow namespaces with aliases to merge when the aliases look to be type-only
* Better support for module.exports = class expression
* Fix discovered crash bug
* Allow export assigned class expressions to be reachable symbols from external declarations
* Add missing semicolon
* Support @enum tag post-merge
* preserve comments on signatures and declarations where possible
* Basic support for js classy functions
* Add example we should do better with
* Prototype assignments make things a bit wonky, but the example from the PR seems OK
* Make a ton of changes to support the new way js classes are bound
* Remove some old comments, fix import and export default names
* Fix bug in object define handling and add tests for object define property declaration emit
* Fix organization nits from PR comments
* Preserve comments from jsdoc declarations on properties and js declaration type aliases
* Merge export declarations with identical specifiers
* Remove completed TODO comment
* Split lint
* Remove now-unused function
* PR feedback
* Add some project references tests, remove some checks from project refs codepaths that are now invalid
* Update project references tests again
* Merge and update project references tests
* Rename case
* Update test to include declaration output
* Remove yet another project refernces redirect extension check
* Update comment
* Add additional import ref to test
* Add shorthand prop to test
* Fix comment text
* Extract var to temp
* Simplify function and add whitespace
* Update project refs test to use incremental edit entry
* Stylistic refactors in the symbol serializer
* Another round of PR feedback, mostly style, small bugfix with constructors, and test showing bug in export assigned class expression name shadowing
* Use x instead of index
2019-09-26 23:27:16 +02:00
if ( getEmitDeclarations ( configFile . options ) ) {
2020-12-07 20:53:22 +01:00
return getOutputDeclarationFileName ( inputFileName , configFile , ignoreCase , getCommonSourceDirectory ) ;
2019-08-31 01:33:44 +02:00
}
2019-03-13 17:58:26 +01:00
}
2019-09-18 23:02:41 +02:00
const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( configFile . options ) ;
2019-03-14 17:21:20 +01:00
if ( buildInfoPath ) return buildInfoPath ;
2019-03-13 17:58:26 +01:00
return Debug . fail ( ` project ${ configFile . options . configFilePath } expected to have at least one output ` ) ;
}
2017-01-30 21:27:24 +01:00
/*@internal*/
2015-02-06 03:26:56 +01:00
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
2019-09-10 01:16:57 +02:00
export function emitFiles ( resolver : EmitResolver , host : EmitHost , targetSourceFile : SourceFile | undefined , { scriptTransformers , declarationTransformers } : EmitTransformers , emitOnlyDtsFiles? : boolean , onlyBuildInfo? : boolean , forceDtsEmit? : boolean ) : EmitResult {
2015-11-04 23:02:33 +01:00
const compilerOptions = host . getCompilerOptions ( ) ;
2018-09-05 02:50:06 +02:00
const sourceMapDataList : SourceMapEmitResult [ ] | undefined = ( compilerOptions . sourceMap || compilerOptions . inlineSourceMap || getAreDeclarationMapsEnabled ( compilerOptions ) ) ? [ ] : undefined ;
2018-05-22 23:46:57 +02:00
const emittedFilesList : string [ ] | undefined = compilerOptions . listEmittedFiles ? [ ] : undefined ;
2015-11-06 21:39:42 +01:00
const emitterDiagnostics = createDiagnosticCollection ( ) ;
2018-08-22 21:42:36 +02:00
const newLine = getNewLineCharacter ( compilerOptions , ( ) = > host . getNewLine ( ) ) ;
2016-06-07 19:32:03 +02:00
const writer = createTextWriter ( newLine ) ;
2018-09-07 23:11:54 +02:00
const { enter , exit } = performance . createTimer ( "printTime" , "beforePrint" , "afterPrint" ) ;
2019-02-07 23:25:16 +01:00
let bundleBuildInfo : BundleBuildInfo | undefined ;
2016-06-07 19:32:03 +02:00
let emitSkipped = false ;
2018-07-11 22:34:30 +02:00
let exportedModulesFromDeclarationEmit : ExportedModulesFromDeclarationEmit | undefined ;
2016-06-07 19:32:03 +02:00
// Emit each output file
2018-09-07 23:11:54 +02:00
enter ( ) ;
2019-09-10 01:16:57 +02:00
forEachEmittedFile (
host ,
emitSourceFileOrBundle ,
2019-11-27 22:47:19 +01:00
getSourceFilesToEmit ( host , targetSourceFile , forceDtsEmit ) ,
2019-09-10 01:16:57 +02:00
forceDtsEmit ,
onlyBuildInfo ,
! targetSourceFile
) ;
2018-09-07 23:11:54 +02:00
exit ( ) ;
2015-02-05 23:46:50 +01:00
2016-09-27 00:21:03 +02:00
2015-02-05 23:46:50 +01:00
return {
2015-10-21 00:51:37 +02:00
emitSkipped ,
2015-10-30 21:43:52 +01:00
diagnostics : emitterDiagnostics.getDiagnostics ( ) ,
2016-04-06 22:25:29 +02:00
emittedFiles : emittedFilesList ,
2018-05-22 23:46:57 +02:00
sourceMaps : sourceMapDataList ,
2018-07-11 22:34:30 +02:00
exportedModulesFromDeclarationEmit
2015-02-05 23:46:50 +01:00
} ;
2019-02-05 21:30:20 +01:00
function emitSourceFileOrBundle ( { jsFilePath , sourceMapFilePath , declarationFilePath , declarationMapPath , buildInfoPath } : EmitFileNames , sourceFileOrBundle : SourceFile | Bundle | undefined ) {
2019-06-19 22:17:26 +02:00
let buildInfoDirectory : string | undefined ;
2019-02-07 23:25:16 +01:00
if ( buildInfoPath && sourceFileOrBundle && isBundle ( sourceFileOrBundle ) ) {
2019-06-20 21:44:20 +02:00
buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
2019-02-22 01:47:58 +01:00
bundleBuildInfo = {
2019-06-19 22:17:26 +02:00
commonSourceDirectory : relativeToBuildInfo ( host . getCommonSourceDirectory ( ) ) ,
2019-06-20 21:44:20 +02:00
sourceFiles : sourceFileOrBundle.sourceFiles.map ( file = > relativeToBuildInfo ( getNormalizedAbsolutePath ( file . fileName , host . getCurrentDirectory ( ) ) ) )
2019-02-22 01:47:58 +01:00
} ;
2019-02-07 23:25:16 +01:00
}
2021-01-13 22:01:53 +01:00
tracing ? . push ( tracing . Phase . Emit , "emitJsFileOrBundle" , { jsFilePath } ) ;
2019-06-19 22:17:26 +02:00
emitJsFileOrBundle ( sourceFileOrBundle , jsFilePath , sourceMapFilePath , relativeToBuildInfo ) ;
2021-01-13 22:01:53 +01:00
tracing ? . pop ( ) ;
2020-08-06 20:02:51 +02:00
2021-01-13 22:01:53 +01:00
tracing ? . push ( tracing . Phase . Emit , "emitDeclarationFileOrBundle" , { declarationFilePath } ) ;
2019-06-19 22:17:26 +02:00
emitDeclarationFileOrBundle ( sourceFileOrBundle , declarationFilePath , declarationMapPath , relativeToBuildInfo ) ;
2021-01-13 22:01:53 +01:00
tracing ? . pop ( ) ;
2020-08-06 20:02:51 +02:00
2021-01-13 22:01:53 +01:00
tracing ? . push ( tracing . Phase . Emit , "emitBuildInfo" , { buildInfoPath } ) ;
2019-02-07 23:25:16 +01:00
emitBuildInfo ( bundleBuildInfo , buildInfoPath ) ;
2021-01-13 22:01:53 +01:00
tracing ? . pop ( ) ;
2015-10-11 10:12:26 +02:00
2016-06-07 19:32:03 +02:00
if ( ! emitSkipped && emittedFilesList ) {
2016-09-27 23:02:10 +02:00
if ( ! emitOnlyDtsFiles ) {
2018-10-11 19:09:47 +02:00
if ( jsFilePath ) {
emittedFilesList . push ( jsFilePath ) ;
}
if ( sourceMapFilePath ) {
emittedFilesList . push ( sourceMapFilePath ) ;
}
2019-01-30 19:01:49 +01:00
if ( buildInfoPath ) {
emittedFilesList . push ( buildInfoPath ) ;
2018-10-11 19:09:47 +02:00
}
2015-10-11 10:12:26 +02:00
}
2016-06-07 19:32:03 +02:00
if ( declarationFilePath ) {
emittedFilesList . push ( declarationFilePath ) ;
2015-10-11 10:12:26 +02:00
}
2018-10-11 19:09:47 +02:00
if ( declarationMapPath ) {
emittedFilesList . push ( declarationMapPath ) ;
2018-05-08 00:12:50 +02:00
}
2015-10-11 10:12:26 +02:00
}
2019-06-19 22:17:26 +02:00
function relativeToBuildInfo ( path : string ) {
return ensurePathIsNonModuleName ( getRelativePathFromDirectory ( buildInfoDirectory ! , path , host . getCanonicalFileName ) ) ;
}
2015-10-11 10:12:26 +02:00
}
2019-02-07 23:25:16 +01:00
function emitBuildInfo ( bundle : BundleBuildInfo | undefined , buildInfoPath : string | undefined ) {
2019-02-05 21:30:20 +01:00
// Write build information if applicable
2019-02-20 21:55:08 +01:00
if ( ! buildInfoPath || targetSourceFile || emitSkipped ) return ;
2019-02-06 04:35:08 +01:00
const program = host . getProgramBuildInfo ( ) ;
2020-06-18 20:05:37 +02:00
if ( host . isEmitBlocked ( buildInfoPath ) ) {
2019-02-22 04:05:30 +01:00
emitSkipped = true ;
return ;
}
2019-12-02 22:44:25 +01:00
const version = ts . version ; // Extracted into a const so the form is stable between namespace and module
2019-03-08 22:05:19 +01:00
writeFile ( host , emitterDiagnostics , buildInfoPath , getBuildInfoText ( { bundle , program , version } ) , /*writeByteOrderMark*/ false ) ;
2019-02-05 21:30:20 +01:00
}
2019-06-19 22:17:26 +02:00
function emitJsFileOrBundle (
sourceFileOrBundle : SourceFile | Bundle | undefined ,
jsFilePath : string | undefined ,
sourceMapFilePath : string | undefined ,
relativeToBuildInfo : ( path : string ) = > string ) {
2019-02-05 21:30:20 +01:00
if ( ! sourceFileOrBundle || emitOnlyDtsFiles || ! jsFilePath ) {
2018-03-16 06:23:10 +01:00
return ;
}
2018-10-11 19:09:47 +02:00
// Make sure not to write js file and source map file if any of them cannot be written
if ( ( jsFilePath && host . isEmitBlocked ( jsFilePath ) ) || compilerOptions . noEmit ) {
emitSkipped = true ;
2018-03-16 06:23:10 +01:00
return ;
}
// Transform the source files
2020-06-17 01:55:03 +02:00
const transform = transformNodes ( resolver , host , factory , compilerOptions , [ sourceFileOrBundle ] , scriptTransformers , /*allowDtsFiles*/ false ) ;
2018-03-16 06:23:10 +01:00
2018-08-22 21:42:36 +02:00
const printerOptions : PrinterOptions = {
removeComments : compilerOptions.removeComments ,
newLine : compilerOptions.newLine ,
noEmitHelpers : compilerOptions.noEmitHelpers ,
module : compilerOptions.module ,
target : compilerOptions.target ,
sourceMap : compilerOptions.sourceMap ,
inlineSourceMap : compilerOptions.inlineSourceMap ,
2018-09-05 02:50:06 +02:00
inlineSources : compilerOptions.inlineSources ,
2018-08-22 21:42:36 +02:00
extendedDiagnostics : compilerOptions.extendedDiagnostics ,
2019-06-19 22:17:26 +02:00
writeBundleFileInfo : ! ! bundleBuildInfo ,
relativeToBuildInfo
2018-08-22 21:42:36 +02:00
} ;
2018-03-16 06:23:10 +01:00
// Create a printer to print the nodes
2018-08-22 21:42:36 +02:00
const printer = createPrinter ( printerOptions , {
2018-03-16 06:23:10 +01:00
// resolver hooks
hasGlobalName : resolver.hasGlobalName ,
// transform hooks
onEmitNode : transform.emitNodeWithNotification ,
2020-01-25 01:29:55 +01:00
isEmitNotificationEnabled : transform.isEmitNotificationEnabled ,
2018-03-16 06:23:10 +01:00
substituteNode : transform.substituteNode ,
} ) ;
2018-05-08 00:12:50 +02:00
Debug . assert ( transform . transformed . length === 1 , "Should only see one output from the transform" ) ;
2019-02-11 22:13:19 +01:00
printSourceFileOrBundle ( jsFilePath , sourceMapFilePath , transform . transformed [ 0 ] , printer , compilerOptions ) ;
2018-03-16 06:23:10 +01:00
// Clean up emit nodes on parse tree
transform . dispose ( ) ;
2019-02-11 22:44:37 +01:00
if ( bundleBuildInfo ) bundleBuildInfo . js = printer . bundleFileInfo ;
2018-03-16 06:23:10 +01:00
}
2019-06-19 22:17:26 +02:00
function emitDeclarationFileOrBundle (
sourceFileOrBundle : SourceFile | Bundle | undefined ,
declarationFilePath : string | undefined ,
declarationMapPath : string | undefined ,
relativeToBuildInfo : ( path : string ) = > string ) {
2019-10-15 19:07:09 +02:00
if ( ! sourceFileOrBundle ) return ;
if ( ! declarationFilePath ) {
if ( emitOnlyDtsFiles || compilerOptions . emitDeclarationOnly ) emitSkipped = true ;
2018-03-16 06:23:10 +01:00
return ;
}
const sourceFiles = isSourceFile ( sourceFileOrBundle ) ? [ sourceFileOrBundle ] : sourceFileOrBundle . sourceFiles ;
2020-01-08 18:54:32 +01:00
const filesForEmit = forceDtsEmit ? sourceFiles : filter ( sourceFiles , isSourceFileNotJson ) ;
2018-03-16 06:23:10 +01:00
// Setup and perform the transformation to retrieve declarations from the input files
2020-06-17 01:55:03 +02:00
const inputListOrBundle = outFile ( compilerOptions ) ? [ factory . createBundle ( filesForEmit , ! isSourceFile ( sourceFileOrBundle ) ? sourceFileOrBundle.prepends : undefined ) ] : filesForEmit ;
2018-07-09 21:32:52 +02:00
if ( emitOnlyDtsFiles && ! getEmitDeclarations ( compilerOptions ) ) {
2018-06-20 21:25:51 +02:00
// Checker wont collect the linked aliases since thats only done when declaration is enabled.
// Do that here when emitting only dts files
2020-01-08 18:54:32 +01:00
filesForEmit . forEach ( collectLinkedAliases ) ;
2018-06-20 21:25:51 +02:00
}
2020-06-17 01:55:03 +02:00
const declarationTransform = transformNodes ( resolver , host , factory , compilerOptions , inputListOrBundle , declarationTransformers , /*allowDtsFiles*/ false ) ;
2018-03-16 06:23:10 +01:00
if ( length ( declarationTransform . diagnostics ) ) {
2018-05-22 23:46:57 +02:00
for ( const diagnostic of declarationTransform . diagnostics ! ) {
2018-03-16 06:23:10 +01:00
emitterDiagnostics . add ( diagnostic ) ;
}
}
2018-08-22 21:42:36 +02:00
const printerOptions : PrinterOptions = {
removeComments : compilerOptions.removeComments ,
newLine : compilerOptions.newLine ,
noEmitHelpers : true ,
module : compilerOptions.module ,
target : compilerOptions.target ,
sourceMap : compilerOptions.sourceMap ,
inlineSourceMap : compilerOptions.inlineSourceMap ,
extendedDiagnostics : compilerOptions.extendedDiagnostics ,
onlyPrintJsDocStyle : true ,
2019-02-15 23:25:24 +01:00
writeBundleFileInfo : ! ! bundleBuildInfo ,
2019-06-19 22:17:26 +02:00
recordInternalSection : ! ! bundleBuildInfo ,
relativeToBuildInfo
2018-08-22 21:42:36 +02:00
} ;
const declarationPrinter = createPrinter ( printerOptions , {
2018-03-16 06:23:10 +01:00
// resolver hooks
hasGlobalName : resolver.hasGlobalName ,
// transform hooks
onEmitNode : declarationTransform.emitNodeWithNotification ,
2020-01-25 01:29:55 +01:00
isEmitNotificationEnabled : declarationTransform.isEmitNotificationEnabled ,
2018-03-16 06:23:10 +01:00
substituteNode : declarationTransform.substituteNode ,
} ) ;
const declBlocked = ( ! ! declarationTransform . diagnostics && ! ! declarationTransform . diagnostics . length ) || ! ! host . isEmitBlocked ( declarationFilePath ) || ! ! compilerOptions . noEmit ;
emitSkipped = emitSkipped || declBlocked ;
2019-09-10 01:16:57 +02:00
if ( ! declBlocked || forceDtsEmit ) {
2018-05-08 00:12:50 +02:00
Debug . assert ( declarationTransform . transformed . length === 1 , "Should only see one output from the decl transform" ) ;
2019-02-07 23:25:16 +01:00
printSourceFileOrBundle (
declarationFilePath ,
declarationMapPath ,
declarationTransform . transformed [ 0 ] ,
declarationPrinter ,
{
2021-03-12 18:44:22 +01:00
sourceMap : ! forceDtsEmit && compilerOptions . declarationMap ,
2019-02-07 23:25:16 +01:00
sourceRoot : compilerOptions.sourceRoot ,
mapRoot : compilerOptions.mapRoot ,
extendedDiagnostics : compilerOptions.extendedDiagnostics ,
// Explicitly do not passthru either `inline` option
}
) ;
2019-09-10 01:16:57 +02:00
if ( forceDtsEmit && declarationTransform . transformed [ 0 ] . kind === SyntaxKind . SourceFile ) {
2019-08-16 10:52:34 +02:00
const sourceFile = declarationTransform . transformed [ 0 ] ;
2018-08-01 21:20:54 +02:00
exportedModulesFromDeclarationEmit = sourceFile . exportedModulesFromDeclarationEmit ;
2018-07-11 22:34:30 +02:00
}
2018-03-16 06:23:10 +01:00
}
declarationTransform . dispose ( ) ;
2019-02-11 22:44:37 +01:00
if ( bundleBuildInfo ) bundleBuildInfo . dts = declarationPrinter . bundleFileInfo ;
2018-03-16 06:23:10 +01:00
}
2018-06-20 21:25:51 +02:00
function collectLinkedAliases ( node : Node ) {
if ( isExportAssignment ( node ) ) {
if ( node . expression . kind === SyntaxKind . Identifier ) {
resolver . collectLinkedAliases ( node . expression as Identifier , /*setVisibility*/ true ) ;
}
return ;
}
else if ( isExportSpecifier ( node ) ) {
resolver . collectLinkedAliases ( node . propertyName || node . name , /*setVisibility*/ true ) ;
return ;
}
forEachChild ( node , collectLinkedAliases ) ;
}
2019-02-11 22:13:19 +01:00
function printSourceFileOrBundle ( jsFilePath : string , sourceMapFilePath : string | undefined , sourceFileOrBundle : SourceFile | Bundle , printer : Printer , mapOptions : SourceMapOptions ) {
2017-01-27 00:46:26 +01:00
const bundle = sourceFileOrBundle . kind === SyntaxKind . Bundle ? sourceFileOrBundle : undefined ;
const sourceFile = sourceFileOrBundle . kind === SyntaxKind . SourceFile ? sourceFileOrBundle : undefined ;
2018-05-22 23:46:57 +02:00
const sourceFiles = bundle ? bundle . sourceFiles : [ sourceFile ! ] ;
2015-11-24 07:38:05 +01:00
2018-09-05 02:50:06 +02:00
let sourceMapGenerator : SourceMapGenerator | undefined ;
if ( shouldEmitSourceMaps ( mapOptions , sourceFileOrBundle ) ) {
sourceMapGenerator = createSourceMapGenerator (
host ,
getBaseFileName ( normalizeSlashes ( jsFilePath ) ) ,
getSourceRoot ( mapOptions ) ,
getSourceMapDirectory ( mapOptions , jsFilePath , sourceFile ) ,
mapOptions ) ;
2016-06-07 19:32:03 +02:00
}
2015-11-24 07:38:05 +01:00
2018-09-05 02:50:06 +02:00
if ( bundle ) {
2019-02-11 22:13:19 +01:00
printer . writeBundle ( bundle , writer , sourceMapGenerator ) ;
2018-08-22 21:42:36 +02:00
}
else {
2018-09-05 02:50:06 +02:00
printer . writeFile ( sourceFile ! , writer , sourceMapGenerator ) ;
2015-02-14 09:48:46 +01:00
}
2018-09-05 02:50:06 +02:00
if ( sourceMapGenerator ) {
if ( sourceMapDataList ) {
sourceMapDataList . push ( {
inputSourceFileNames : sourceMapGenerator.getSources ( ) ,
sourceMap : sourceMapGenerator.toJSON ( )
} ) ;
}
const sourceMappingURL = getSourceMappingURL (
mapOptions ,
sourceMapGenerator ,
jsFilePath ,
sourceMapFilePath ,
sourceFile ) ;
if ( sourceMappingURL ) {
if ( ! writer . isAtStartOfLine ( ) ) writer . rawWrite ( newLine ) ;
writer . writeComment ( ` //# ${ "sourceMappingURL" } = ${ sourceMappingURL } ` ) ; // Tools can sometimes see this line as a source mapping url comment
}
// Write the source map
if ( sourceMapFilePath ) {
const sourceMap = sourceMapGenerator . toString ( ) ;
2018-08-22 21:42:36 +02:00
writeFile ( host , emitterDiagnostics , sourceMapFilePath , sourceMap , /*writeByteOrderMark*/ false , sourceFiles ) ;
}
2015-03-24 00:16:29 +01:00
}
2018-09-05 02:50:06 +02:00
else {
writer . writeLine ( ) ;
}
2015-03-24 00:16:29 +01:00
2016-06-07 19:32:03 +02:00
// Write the output file
2018-05-22 23:46:57 +02:00
writeFile ( host , emitterDiagnostics , jsFilePath , writer . getText ( ) , ! ! compilerOptions . emitBOM , sourceFiles ) ;
2015-03-26 18:51:07 +01:00
2016-06-07 19:32:03 +02:00
// Reset state
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writer . clear ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-24 00:16:29 +01:00
2018-09-05 02:50:06 +02:00
interface SourceMapOptions {
sourceMap? : boolean ;
inlineSourceMap? : boolean ;
inlineSources? : boolean ;
sourceRoot? : string ;
mapRoot? : string ;
extendedDiagnostics? : boolean ;
}
function shouldEmitSourceMaps ( mapOptions : SourceMapOptions , sourceFileOrBundle : SourceFile | Bundle ) {
return ( mapOptions . sourceMap || mapOptions . inlineSourceMap )
&& ( sourceFileOrBundle . kind !== SyntaxKind . SourceFile || ! fileExtensionIs ( sourceFileOrBundle . fileName , Extension . Json ) ) ;
}
function getSourceRoot ( mapOptions : SourceMapOptions ) {
// Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the
// relative paths of the sources list in the sourcemap
const sourceRoot = normalizeSlashes ( mapOptions . sourceRoot || "" ) ;
return sourceRoot ? ensureTrailingDirectorySeparator ( sourceRoot ) : sourceRoot ;
2016-06-07 19:32:03 +02:00
}
2015-02-14 09:48:46 +01:00
2018-09-05 02:50:06 +02:00
function getSourceMapDirectory ( mapOptions : SourceMapOptions , filePath : string , sourceFile : SourceFile | undefined ) {
if ( mapOptions . sourceRoot ) return host . getCommonSourceDirectory ( ) ;
if ( mapOptions . mapRoot ) {
let sourceMapDir = normalizeSlashes ( mapOptions . mapRoot ) ;
if ( sourceFile ) {
// For modules or multiple emit files the mapRoot will have directory structure like the sources
// So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
sourceMapDir = getDirectoryPath ( getSourceFilePathInNewDir ( sourceFile . fileName , host , sourceMapDir ) ) ;
}
if ( getRootLength ( sourceMapDir ) === 0 ) {
// The relative paths are relative to the common directory
sourceMapDir = combinePaths ( host . getCommonSourceDirectory ( ) , sourceMapDir ) ;
}
return sourceMapDir ;
}
return getDirectoryPath ( normalizePath ( filePath ) ) ;
}
function getSourceMappingURL ( mapOptions : SourceMapOptions , sourceMapGenerator : SourceMapGenerator , filePath : string , sourceMapFilePath : string | undefined , sourceFile : SourceFile | undefined ) {
if ( mapOptions . inlineSourceMap ) {
// Encode the sourceMap into the sourceMap url
const sourceMapText = sourceMapGenerator . toString ( ) ;
const base64SourceMapText = base64encode ( sys , sourceMapText ) ;
return ` data:application/json;base64, ${ base64SourceMapText } ` ;
}
2020-02-25 03:20:58 +01:00
const sourceMapFile = getBaseFileName ( normalizeSlashes ( Debug . checkDefined ( sourceMapFilePath ) ) ) ;
2018-09-05 02:50:06 +02:00
if ( mapOptions . mapRoot ) {
let sourceMapDir = normalizeSlashes ( mapOptions . mapRoot ) ;
if ( sourceFile ) {
// For modules or multiple emit files the mapRoot will have directory structure like the sources
// So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
sourceMapDir = getDirectoryPath ( getSourceFilePathInNewDir ( sourceFile . fileName , host , sourceMapDir ) ) ;
}
if ( getRootLength ( sourceMapDir ) === 0 ) {
// The relative paths are relative to the common directory
sourceMapDir = combinePaths ( host . getCommonSourceDirectory ( ) , sourceMapDir ) ;
2020-10-20 22:11:52 +02:00
return encodeURI (
getRelativePathToDirectoryOrUrl (
getDirectoryPath ( normalizePath ( filePath ) ) , // get the relative sourceMapDir path based on jsFilePath
combinePaths ( sourceMapDir , sourceMapFile ) , // this is where user expects to see sourceMap
host . getCurrentDirectory ( ) ,
host . getCanonicalFileName ,
/*isAbsolutePathAnUrl*/ true ) ) ;
2018-09-05 02:50:06 +02:00
}
else {
2020-10-20 22:11:52 +02:00
return encodeURI ( combinePaths ( sourceMapDir , sourceMapFile ) ) ;
2018-09-05 02:50:06 +02:00
}
}
2020-10-20 22:11:52 +02:00
return encodeURI ( sourceMapFile ) ;
2018-03-26 21:15:34 +02:00
}
2014-07-13 01:04:16 +02:00
}
2015-10-01 00:45:23 +02:00
2019-02-21 22:43:03 +01:00
/*@internal*/
export function getBuildInfoText ( buildInfo : BuildInfo ) {
2021-03-10 01:15:26 +01:00
return JSON . stringify ( buildInfo ) ;
2019-02-01 23:46:58 +01:00
}
2019-03-09 00:05:30 +01:00
/*@internal*/
export function getBuildInfo ( buildInfoText : string ) {
return JSON . parse ( buildInfoText ) as BuildInfo ;
}
2019-02-06 04:35:08 +01:00
/*@internal*/
export const notImplementedResolver : EmitResolver = {
2019-02-01 23:46:58 +01:00
hasGlobalName : notImplemented ,
getReferencedExportContainer : notImplemented ,
getReferencedImportDeclaration : notImplemented ,
getReferencedDeclarationWithCollidingName : notImplemented ,
isDeclarationWithCollidingName : notImplemented ,
isValueAliasDeclaration : notImplemented ,
isReferencedAliasDeclaration : notImplemented ,
isTopLevelValueImportEqualsWithEntityName : notImplemented ,
getNodeCheckFlags : notImplemented ,
isDeclarationVisible : notImplemented ,
isLateBound : ( _node ) : _node is LateBoundDeclaration = > false ,
collectLinkedAliases : notImplemented ,
isImplementationOfOverload : notImplemented ,
isRequiredInitializedParameter : notImplemented ,
isOptionalUninitializedParameterProperty : notImplemented ,
isExpandoFunctionDeclaration : notImplemented ,
getPropertiesOfContainerFunction : notImplemented ,
createTypeOfDeclaration : notImplemented ,
createReturnTypeOfSignatureDeclaration : notImplemented ,
createTypeOfExpression : notImplemented ,
createLiteralConstValue : notImplemented ,
isSymbolAccessible : notImplemented ,
isEntityNameVisible : notImplemented ,
// Returns the constant value this property access resolves to: notImplemented, or 'undefined' for a non-constant
getConstantValue : notImplemented ,
getReferencedValueDeclaration : notImplemented ,
getTypeReferenceSerializationKind : notImplemented ,
isOptionalParameter : notImplemented ,
module ExportsSomeValue : notImplemented ,
isArgumentsLocalBinding : notImplemented ,
getExternalModuleFileFromDeclaration : notImplemented ,
getTypeReferenceDirectivesForEntityName : notImplemented ,
getTypeReferenceDirectivesForSymbol : notImplemented ,
isLiteralConstDeclaration : notImplemented ,
getJsxFactoryEntity : notImplemented ,
2020-06-18 09:22:32 +02:00
getJsxFragmentFactoryEntity : notImplemented ,
2019-02-01 23:46:58 +01:00
getAllAccessorDeclarations : notImplemented ,
getSymbolOfExternalModuleSpecifier : notImplemented ,
isBindingCapturedByNode : notImplemented ,
Allow `allowJs` and `declaration` to be used together (#32372)
* Allow allowJs and declaration to be used together
This intorduces a new symbol-based declaration emitter - currently this
is only used for JSON and JavaScript, as the output is likely worse than
what the other declaration emitter is capable of. In addition, it is
still incomplete - it does not yet support serializaing namespaces.
* Add tests for various import/export forms, add notes on export as namespace and fix export * from
* Tests & fixes for computed names
* Add test with current @enum tag behavior
* fix declaration emit for jsdoc @enum tags
* Small adjustments to base class serialization to fix bugs in it
* Guard against type/type parameter confusion when using typeParameterToName a bit
* Integrate feedback from PR
* Fix issue with export= declarations visibility calculation and type declaration emit that impacted all forms of declaration emit
* Only make one merged getCommonJsExportEquals symbol for a symbol
* Support preserving type reference directives in js declarations
* Skip declare mdoifiers for namespace members in ambient contexts
* FAKE ALIASES AND NAMESPACES EVERYWHERE
* Dont do namespace sugar when type members contain keyword names
* Fix json source file export modifier under new output
* Such clean nested aliasing, very wow
* Fix lint
* Add visibility errors, reuse type nodes where possible
* Suppoer having correctly named import types in bundled js declaration emit & adjust binding to allow namespaces with aliases to merge when the aliases look to be type-only
* Better support for module.exports = class expression
* Fix discovered crash bug
* Allow export assigned class expressions to be reachable symbols from external declarations
* Add missing semicolon
* Support @enum tag post-merge
* preserve comments on signatures and declarations where possible
* Basic support for js classy functions
* Add example we should do better with
* Prototype assignments make things a bit wonky, but the example from the PR seems OK
* Make a ton of changes to support the new way js classes are bound
* Remove some old comments, fix import and export default names
* Fix bug in object define handling and add tests for object define property declaration emit
* Fix organization nits from PR comments
* Preserve comments from jsdoc declarations on properties and js declaration type aliases
* Merge export declarations with identical specifiers
* Remove completed TODO comment
* Split lint
* Remove now-unused function
* PR feedback
* Add some project references tests, remove some checks from project refs codepaths that are now invalid
* Update project references tests again
* Merge and update project references tests
* Rename case
* Update test to include declaration output
* Remove yet another project refernces redirect extension check
* Update comment
* Add additional import ref to test
* Add shorthand prop to test
* Fix comment text
* Extract var to temp
* Simplify function and add whitespace
* Update project refs test to use incremental edit entry
* Stylistic refactors in the symbol serializer
* Another round of PR feedback, mostly style, small bugfix with constructors, and test showing bug in export assigned class expression name shadowing
* Use x instead of index
2019-09-26 23:27:16 +02:00
getDeclarationStatementsForSourceFile : notImplemented ,
2020-04-13 21:31:14 +02:00
isImportRequiredByAugmentation : notImplemented ,
2019-02-01 23:46:58 +01:00
} ;
/*@internal*/
/** File that isnt present resulting in error or output files */
2019-08-08 20:30:18 +02:00
export type EmitUsingBuildInfoResult = string | readonly OutputFile [ ] ;
2019-02-01 23:46:58 +01:00
/*@internal*/
export interface EmitUsingBuildInfoHost extends ModuleResolutionHost {
getCurrentDirectory ( ) : string ;
getCanonicalFileName ( fileName : string ) : string ;
useCaseSensitiveFileNames ( ) : boolean ;
getNewLine ( ) : string ;
}
2019-08-08 20:30:18 +02:00
function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : readonly SourceFile [ ] {
2020-06-17 01:55:03 +02:00
const jsBundle = Debug . checkDefined ( bundle . js ) ;
2020-06-26 01:03:25 +02:00
const prologueMap = jsBundle . sources ? . prologues && arrayToMap ( jsBundle . sources . prologues , prologueInfo = > prologueInfo . file ) ;
2020-06-17 01:55:03 +02:00
return bundle . sourceFiles . map ( ( fileName , index ) = > {
2020-06-26 01:03:25 +02:00
const prologueInfo = prologueMap ? . get ( index ) ;
2020-06-17 01:55:03 +02:00
const statements = prologueInfo ? . directives . map ( directive = > {
const literal = setTextRange ( factory . createStringLiteral ( directive . expression . text ) , directive . expression ) ;
const statement = setTextRange ( factory . createExpressionStatement ( literal ) , directive ) ;
setParent ( literal , statement ) ;
return statement ;
} ) ;
const eofToken = factory . createToken ( SyntaxKind . EndOfFileToken ) ;
const sourceFile = factory . createSourceFile ( statements ? ? [ ] , eofToken , NodeFlags . None ) ;
2019-06-20 21:44:20 +02:00
sourceFile . fileName = getRelativePathFromDirectory (
host . getCurrentDirectory ( ) ,
getNormalizedAbsolutePath ( fileName , buildInfoDirectory ) ,
! host . useCaseSensitiveFileNames ( )
) ;
2020-06-17 01:55:03 +02:00
sourceFile . text = prologueInfo ? . text ? ? "" ;
setTextRangePosWidth ( sourceFile , 0 , prologueInfo ? . text . length ? ? 0 ) ;
setEachParent ( sourceFile . statements , sourceFile ) ;
setTextRangePosWidth ( eofToken , sourceFile . end , 0 ) ;
setParent ( eofToken , sourceFile ) ;
2019-02-22 01:47:58 +01:00
return sourceFile ;
} ) ;
2019-02-05 00:22:23 +01:00
}
2019-02-01 23:46:58 +01:00
/*@internal*/
2019-05-10 00:30:16 +02:00
export function emitUsingBuildInfo (
config : ParsedCommandLine ,
host : EmitUsingBuildInfoHost ,
getCommandLine : ( ref : ProjectReference ) = > ParsedCommandLine | undefined ,
customTransformers? : CustomTransformers
) : EmitUsingBuildInfoResult {
2019-02-28 01:15:09 +01:00
const { buildInfoPath , jsFilePath , sourceMapFilePath , declarationFilePath , declarationMapPath } = getOutputPathsForBundle ( config . options , /*forceDtsPaths*/ false ) ;
2020-02-25 03:20:58 +01:00
const buildInfoText = host . readFile ( Debug . checkDefined ( buildInfoPath ) ) ;
2019-02-01 23:46:58 +01:00
if ( ! buildInfoText ) return buildInfoPath ! ;
2020-02-25 03:20:58 +01:00
const jsFileText = host . readFile ( Debug . checkDefined ( jsFilePath ) ) ;
2019-02-01 23:46:58 +01:00
if ( ! jsFileText ) return jsFilePath ! ;
const sourceMapText = sourceMapFilePath && host . readFile ( sourceMapFilePath ) ;
// error if no source map or for now if inline sourcemap
if ( ( sourceMapFilePath && ! sourceMapText ) || config . options . inlineSourceMap ) return sourceMapFilePath || "inline sourcemap decoding" ;
2019-02-21 01:16:41 +01:00
// read declaration text
2019-02-21 19:19:48 +01:00
const declarationText = declarationFilePath && host . readFile ( declarationFilePath ) ;
if ( declarationFilePath && ! declarationText ) return declarationFilePath ;
2019-02-02 03:40:04 +01:00
const declarationMapText = declarationMapPath && host . readFile ( declarationMapPath ) ;
// error if no source map or for now if inline sourcemap
if ( ( declarationMapPath && ! declarationMapText ) || config . options . inlineSourceMap ) return declarationMapPath || "inline sourcemap decoding" ;
2019-02-01 23:46:58 +01:00
2019-03-09 00:05:30 +01:00
const buildInfo = getBuildInfo ( buildInfoText ) ;
2019-02-21 21:28:15 +01:00
if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationText && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
2019-06-20 21:44:20 +02:00
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath ! , host . getCurrentDirectory ( ) ) ) ;
2019-02-01 23:46:58 +01:00
const ownPrependInput = createInputFiles (
jsFileText ,
2019-02-02 03:40:04 +01:00
declarationText ! ,
2019-02-01 23:46:58 +01:00
sourceMapFilePath ,
sourceMapText ,
2019-02-02 03:40:04 +01:00
declarationMapPath ,
declarationMapText ,
2019-02-01 23:46:58 +01:00
jsFilePath ,
2019-02-02 03:40:04 +01:00
declarationFilePath ,
2019-02-01 23:46:58 +01:00
buildInfoPath ,
buildInfo ,
/*onlyOwnText*/ true
) ;
const outputFiles : OutputFile [ ] = [ ] ;
2019-02-02 05:10:31 +01:00
const prependNodes = createPrependNodes ( config . projectReferences , getCommandLine , f = > host . readFile ( f ) ) ;
2019-06-20 21:44:20 +02:00
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo ( buildInfo . bundle , buildInfoDirectory , host ) ;
2019-02-01 23:46:58 +01:00
const emitHost : EmitHost = {
2019-02-21 01:16:41 +01:00
getPrependNodes : memoize ( ( ) = > [ . . . prependNodes , ownPrependInput ] ) ,
2019-02-01 23:46:58 +01:00
getCanonicalFileName : host.getCanonicalFileName ,
2019-06-19 22:17:26 +02:00
getCommonSourceDirectory : ( ) = > getNormalizedAbsolutePath ( buildInfo . bundle ! . commonSourceDirectory , buildInfoDirectory ) ,
2019-02-21 01:16:41 +01:00
getCompilerOptions : ( ) = > config . options ,
2019-02-01 23:46:58 +01:00
getCurrentDirectory : ( ) = > host . getCurrentDirectory ( ) ,
getNewLine : ( ) = > host . getNewLine ( ) ,
2019-03-14 18:58:57 +01:00
getSourceFile : returnUndefined ,
getSourceFileByPath : returnUndefined ,
2019-02-05 00:22:23 +01:00
getSourceFiles : ( ) = > sourceFilesForJsEmit ,
2019-02-01 23:46:58 +01:00
getLibFileFromReference : notImplemented ,
2019-02-05 00:22:23 +01:00
isSourceFileFromExternalLibrary : returnFalse ,
2019-03-14 18:58:57 +01:00
getResolvedProjectReferenceToRedirect : returnUndefined ,
2020-03-20 00:53:44 +01:00
getProjectReferenceRedirect : returnUndefined ,
2019-11-27 22:47:19 +01:00
isSourceOfProjectReferenceRedirect : returnFalse ,
2019-02-01 23:46:58 +01:00
writeFile : ( name , text , writeByteOrderMark ) = > {
2019-02-21 00:14:47 +01:00
switch ( name ) {
case jsFilePath :
2019-02-21 01:16:41 +01:00
if ( jsFileText === text ) return ;
2019-02-21 00:14:47 +01:00
break ;
case sourceMapFilePath :
2019-02-21 01:16:41 +01:00
if ( sourceMapText === text ) return ;
2019-02-21 00:14:47 +01:00
break ;
case buildInfoPath :
2019-03-09 00:05:30 +01:00
const newBuildInfo = getBuildInfo ( text ) ;
2019-02-21 01:16:41 +01:00
newBuildInfo . program = buildInfo . program ;
2019-02-21 21:28:15 +01:00
// Update sourceFileInfo
2019-02-22 01:47:58 +01:00
const { js , dts , sourceFiles } = buildInfo . bundle ! ;
2019-02-21 21:28:15 +01:00
newBuildInfo . bundle ! . js ! . sources = js ! . sources ;
if ( dts ) {
newBuildInfo . bundle ! . dts ! . sources = dts . sources ;
}
2019-02-22 01:47:58 +01:00
newBuildInfo . bundle ! . sourceFiles = sourceFiles ;
2019-02-21 21:28:15 +01:00
outputFiles . push ( { name , text : getBuildInfoText ( newBuildInfo ) , writeByteOrderMark } ) ;
2019-02-21 01:16:41 +01:00
return ;
2019-02-21 00:14:47 +01:00
case declarationFilePath :
2019-02-21 01:16:41 +01:00
if ( declarationText === text ) return ;
2019-02-21 00:14:47 +01:00
break ;
case declarationMapPath :
2019-02-21 01:16:41 +01:00
if ( declarationMapText === text ) return ;
2019-02-21 00:14:47 +01:00
break ;
default :
2019-03-08 19:22:44 +01:00
Debug . fail ( ` Unexpected path: ${ name } ` ) ;
2019-02-01 23:46:58 +01:00
}
2019-02-21 01:16:41 +01:00
outputFiles . push ( { name , text , writeByteOrderMark } ) ;
2019-02-01 23:46:58 +01:00
} ,
isEmitBlocked : returnFalse ,
readFile : f = > host . readFile ( f ) ,
fileExists : f = > host . fileExists ( f ) ,
useCaseSensitiveFileNames : ( ) = > host . useCaseSensitiveFileNames ( ) ,
2019-06-21 22:26:29 +02:00
getProgramBuildInfo : returnUndefined ,
getSourceFileFromReference : returnUndefined ,
2021-01-09 00:20:29 +01:00
redirectTargetsMap : createMultiMap ( ) ,
getFileIncludeReasons : notImplemented ,
2019-02-01 23:46:58 +01:00
} ;
2019-05-10 01:07:47 +02:00
emitFiles (
notImplementedResolver ,
emitHost ,
/*targetSourceFile*/ undefined ,
getTransformers ( config . options , customTransformers )
) ;
2019-02-01 23:46:58 +01:00
return outputFiles ;
}
2021-04-19 18:34:46 +02:00
const enum PipelinePhase {
Notification ,
Substitution ,
Comments ,
SourceMaps ,
Emit ,
}
2017-01-30 21:27:24 +01:00
export function createPrinter ( printerOptions : PrinterOptions = { } , handlers : PrintHandlers = { } ) : Printer {
const {
hasGlobalName ,
2021-04-19 18:34:46 +02:00
onEmitNode = noEmitNotification ,
isEmitNotificationEnabled ,
substituteNode = noEmitSubstitution ,
2021-02-26 08:01:41 +01:00
onBeforeEmitNode ,
onAfterEmitNode ,
2017-03-15 19:44:36 +01:00
onBeforeEmitNodeArray ,
2017-05-19 19:18:42 +02:00
onAfterEmitNodeArray ,
onBeforeEmitToken ,
onAfterEmitToken
2017-01-30 21:27:24 +01:00
} = handlers ;
2018-09-07 23:11:54 +02:00
const extendedDiagnostics = ! ! printerOptions . extendedDiagnostics ;
2017-01-30 21:27:24 +01:00
const newLine = getNewLineCharacter ( printerOptions ) ;
2018-09-05 02:50:06 +02:00
const module Kind = getEmitModuleKind ( printerOptions ) ;
2020-06-26 01:03:25 +02:00
const bundledHelpers = new Map < string , boolean > ( ) ;
2017-01-30 21:27:24 +01:00
2018-11-10 02:18:34 +01:00
let currentSourceFile : SourceFile | undefined ;
2017-01-30 21:27:24 +01:00
let nodeIdToGeneratedName : string [ ] ; // Map of generated names for specific nodes.
let autoGeneratedIdToGeneratedName : string [ ] ; // Map of generated names for temp and loop variables.
2020-06-26 19:12:47 +02:00
let generatedNames : Set < string > ; // Set of names generated by the NameGenerator.
2017-01-30 21:27:24 +01:00
let tempFlagsStack : TempFlags [ ] ; // Stack of enclosing name generation scopes.
let tempFlags : TempFlags ; // TempFlags for the current name generation scope.
2020-06-26 19:12:47 +02:00
let reservedNamesStack : Set < string > [ ] ; // Stack of TempFlags reserved in enclosing name generation scopes.
let reservedNames : Set < string > ; // TempFlags to reserve in nested name generation scopes.
2020-03-19 17:46:00 +01:00
let preserveSourceNewlines = printerOptions . preserveSourceNewlines ; // Can be overridden inside nodes with the `IgnoreSourceNewlines` emit flag.
2020-07-22 19:31:42 +02:00
let nextListElementPos : number | undefined ; // See comment in `getLeadingLineTerminatorCount`.
2018-01-16 21:33:55 +01:00
2017-01-30 21:27:24 +01:00
let writer : EmitTextWriter ;
2018-09-05 02:50:06 +02:00
let ownWriter : EmitTextWriter ; // Reusable `EmitTextWriter` for basic printing.
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
let write = writeBase ;
2018-03-31 02:43:37 +02:00
let isOwnFileEmit : boolean ;
2019-02-11 22:44:37 +01:00
const bundleFileInfo = printerOptions . writeBundleFileInfo ? { sections : [ ] } as BundleFileInfo : undefined ;
2020-02-25 03:20:58 +01:00
const relativeToBuildInfo = bundleFileInfo ? Debug . checkDefined ( printerOptions . relativeToBuildInfo ) : undefined ;
2019-02-15 23:25:24 +01:00
const recordInternalSection = printerOptions . recordInternalSection ;
let sourceFileTextPos = 0 ;
2019-02-22 22:03:46 +01:00
let sourceFileTextKind : BundleFileTextLikeKind = BundleFileSectionKind . Text ;
2017-01-30 21:27:24 +01:00
2018-09-05 02:50:06 +02:00
// Source Maps
let sourceMapsDisabled = true ;
let sourceMapGenerator : SourceMapGenerator | undefined ;
2018-09-07 23:11:54 +02:00
let sourceMapSource : SourceMapSource ;
2018-09-05 02:50:06 +02:00
let sourceMapSourceIndex = - 1 ;
2020-08-20 01:05:32 +02:00
let mostRecentlyAddedSourceMapSource : SourceMapSource ;
let mostRecentlyAddedSourceMapSourceIndex = - 1 ;
2018-09-05 02:50:06 +02:00
// Comments
let containerPos = - 1 ;
let containerEnd = - 1 ;
let declarationListContainerEnd = - 1 ;
2019-08-08 20:30:18 +02:00
let currentLineMap : readonly number [ ] | undefined ;
2021-02-26 19:37:51 +01:00
let detachedCommentsInfo : { nodePos : number , detachedCommentEndPos : number } [ ] | undefined ;
2018-09-05 02:50:06 +02:00
let hasWrittenComment = false ;
let commentsDisabled = ! ! printerOptions . removeComments ;
2021-04-19 18:34:46 +02:00
let lastSubstitution : Node | undefined ;
let currentParenthesizerRule : ( ( node : Node ) = > Node ) | undefined ;
2018-09-07 23:11:54 +02:00
const { enter : enterComment , exit : exitComment } = performance . createTimerIf ( extendedDiagnostics , "commentTime" , "beforeComment" , "afterComment" ) ;
2021-04-19 18:34:46 +02:00
const parenthesizer = factory . parenthesizer ;
2021-02-26 08:01:41 +01:00
const emitBinaryExpression = createEmitBinaryExpression ( ) ;
2018-09-05 02:50:06 +02:00
2017-01-30 21:27:24 +01:00
reset ( ) ;
return {
// public API
printNode ,
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
printList ,
2017-01-30 21:27:24 +01:00
printFile ,
printBundle ,
// internal API
writeNode ,
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeList ,
2017-01-30 21:27:24 +01:00
writeFile ,
2019-02-11 22:13:19 +01:00
writeBundle ,
bundleFileInfo
2017-01-30 21:27:24 +01:00
} ;
function printNode ( hint : EmitHint , node : Node , sourceFile : SourceFile ) : string {
2017-02-02 01:16:04 +01:00
switch ( hint ) {
case EmitHint . SourceFile :
Debug . assert ( isSourceFile ( node ) , "Expected a SourceFile node." ) ;
break ;
case EmitHint . IdentifierName :
Debug . assert ( isIdentifier ( node ) , "Expected an Identifier node." ) ;
break ;
case EmitHint . Expression :
Debug . assert ( isExpression ( node ) , "Expected an Expression node." ) ;
break ;
}
switch ( node . kind ) {
2021-05-18 15:20:57 +02:00
case SyntaxKind.SourceFile : return printFile ( node as SourceFile ) ;
case SyntaxKind.Bundle : return printBundle ( node as Bundle ) ;
case SyntaxKind.UnparsedSource : return printUnparsedSource ( node as UnparsedSource ) ;
2017-02-02 01:16:04 +01:00
}
2017-01-30 21:27:24 +01:00
writeNode ( hint , node , sourceFile , beginPrint ( ) ) ;
return endPrint ( ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
function printList < T extends Node > ( format : ListFormat , nodes : NodeArray < T > , sourceFile : SourceFile ) {
writeList ( format , nodes , sourceFile , beginPrint ( ) ) ;
return endPrint ( ) ;
}
2017-01-30 21:27:24 +01:00
function printBundle ( bundle : Bundle ) : string {
2019-02-11 22:13:19 +01:00
writeBundle ( bundle , beginPrint ( ) , /*sourceMapEmitter*/ undefined ) ;
2017-01-30 21:27:24 +01:00
return endPrint ( ) ;
2016-09-26 20:20:24 +02:00
}
2017-01-30 21:27:24 +01:00
function printFile ( sourceFile : SourceFile ) : string {
2018-09-05 02:50:06 +02:00
writeFile ( sourceFile , beginPrint ( ) , /*sourceMapEmitter*/ undefined ) ;
2017-01-30 21:27:24 +01:00
return endPrint ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-02-18 21:10:00 +01:00
2018-05-08 00:12:50 +02:00
function printUnparsedSource ( unparsed : UnparsedSource ) : string {
writeUnparsedSource ( unparsed , beginPrint ( ) ) ;
return endPrint ( ) ;
}
2017-05-13 01:27:35 +02:00
/ * *
* If ` sourceFile ` is ` undefined ` , ` node ` must be a synthesized ` TypeNode ` .
* /
function writeNode ( hint : EmitHint , node : TypeNode , sourceFile : undefined , output : EmitTextWriter ) : void ;
function writeNode ( hint : EmitHint , node : Node , sourceFile : SourceFile , output : EmitTextWriter ) : void ;
2017-03-30 23:14:15 +02:00
function writeNode ( hint : EmitHint , node : Node , sourceFile : SourceFile | undefined , output : EmitTextWriter ) {
2017-01-30 21:27:24 +01:00
const previousWriter = writer ;
2018-09-05 02:50:06 +02:00
setWriter ( output , /*_sourceMapGenerator*/ undefined ) ;
2017-01-30 21:27:24 +01:00
print ( hint , node , sourceFile ) ;
reset ( ) ;
writer = previousWriter ;
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
function writeList < T extends Node > ( format : ListFormat , nodes : NodeArray < T > , sourceFile : SourceFile | undefined , output : EmitTextWriter ) {
const previousWriter = writer ;
2018-09-05 02:50:06 +02:00
setWriter ( output , /*_sourceMapGenerator*/ undefined ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
if ( sourceFile ) {
setSourceFile ( sourceFile ) ;
}
2021-02-26 08:01:41 +01:00
emitList ( /*parentNode*/ undefined , nodes , format ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
reset ( ) ;
writer = previousWriter ;
}
2019-01-26 01:39:38 +01:00
function getTextPosWithWriteLine() {
return writer . getTextPosWithWriteLine ? writer . getTextPosWithWriteLine ( ) : writer . getTextPos ( ) ;
}
2019-02-15 23:25:24 +01:00
function updateOrPushBundleFileTextLike ( pos : number , end : number , kind : BundleFileTextLikeKind ) {
const last = lastOrUndefined ( bundleFileInfo ! . sections ) ;
if ( last && last . kind === kind ) {
last . end = end ;
}
else {
bundleFileInfo ! . sections . push ( { pos , end , kind } ) ;
}
}
2019-02-22 22:51:13 +01:00
function recordBundleFileInternalSectionStart ( node : Node ) {
if ( recordInternalSection &&
bundleFileInfo &&
currentSourceFile &&
( isDeclaration ( node ) || isVariableStatement ( node ) ) &&
isInternalDeclaration ( node , currentSourceFile ) &&
sourceFileTextKind !== BundleFileSectionKind . Internal ) {
const prevSourceFileTextKind = sourceFileTextKind ;
recordBundleFileTextLikeSection ( writer . getTextPos ( ) ) ;
sourceFileTextPos = getTextPosWithWriteLine ( ) ;
sourceFileTextKind = BundleFileSectionKind . Internal ;
return prevSourceFileTextKind ;
}
return undefined ;
}
function recordBundleFileInternalSectionEnd ( prevSourceFileTextKind : ReturnType < typeof recordBundleFileInternalSectionStart > ) {
if ( prevSourceFileTextKind ) {
recordBundleFileTextLikeSection ( writer . getTextPos ( ) ) ;
sourceFileTextPos = getTextPosWithWriteLine ( ) ;
sourceFileTextKind = prevSourceFileTextKind ;
}
}
2019-02-22 22:03:46 +01:00
function recordBundleFileTextLikeSection ( end : number ) {
2019-02-15 23:25:24 +01:00
if ( sourceFileTextPos < end ) {
2019-02-22 22:03:46 +01:00
updateOrPushBundleFileTextLike ( sourceFileTextPos , end , sourceFileTextKind ) ;
2019-02-15 23:25:24 +01:00
return true ;
}
return false ;
}
2019-02-11 22:13:19 +01:00
function writeBundle ( bundle : Bundle , output : EmitTextWriter , sourceMapGenerator : SourceMapGenerator | undefined ) {
2018-03-31 02:43:37 +02:00
isOwnFileEmit = false ;
2017-01-30 21:27:24 +01:00
const previousWriter = writer ;
2018-09-05 02:50:06 +02:00
setWriter ( output , sourceMapGenerator ) ;
2017-02-24 00:27:22 +01:00
emitShebangIfNeeded ( bundle ) ;
2017-02-24 20:37:34 +01:00
emitPrologueDirectivesIfNeeded ( bundle ) ;
2018-03-31 02:43:37 +02:00
emitHelpers ( bundle ) ;
2018-03-16 06:23:10 +01:00
emitSyntheticTripleSlashReferencesIfNeeded ( bundle ) ;
2018-05-08 00:12:50 +02:00
for ( const prepend of bundle . prepends ) {
writeLine ( ) ;
2019-02-20 21:55:08 +01:00
const pos = writer . getTextPos ( ) ;
2019-02-15 18:46:37 +01:00
const savedSections = bundleFileInfo && bundleFileInfo . sections ;
if ( savedSections ) bundleFileInfo ! . sections = [ ] ;
2018-08-22 21:42:36 +02:00
print ( EmitHint . Unspecified , prepend , /*sourceFile*/ undefined ) ;
2019-02-01 23:46:58 +01:00
if ( bundleFileInfo ) {
2019-02-15 18:46:37 +01:00
const newSections = bundleFileInfo . sections ;
bundleFileInfo . sections = savedSections ! ;
2019-02-20 22:09:38 +01:00
if ( prepend . oldFileOfCurrentEmit ) bundleFileInfo . sections . push ( . . . newSections ) ;
2019-02-15 18:46:37 +01:00
else {
newSections . forEach ( section = > Debug . assert ( isBundleFileTextLike ( section ) ) ) ;
2019-06-19 22:17:26 +02:00
bundleFileInfo . sections . push ( {
pos ,
end : writer.getTextPos ( ) ,
kind : BundleFileSectionKind.Prepend ,
data : relativeToBuildInfo ! ( ( prepend as UnparsedSource ) . fileName ) ,
texts : newSections as BundleFileTextLike [ ]
} ) ;
2019-02-15 18:46:37 +01:00
}
2019-02-01 23:46:58 +01:00
}
2018-05-08 00:12:50 +02:00
}
2019-02-15 23:25:24 +01:00
sourceFileTextPos = getTextPosWithWriteLine ( ) ;
2017-01-30 21:27:24 +01:00
for ( const sourceFile of bundle . sourceFiles ) {
print ( EmitHint . SourceFile , sourceFile , sourceFile ) ;
2016-07-21 03:43:41 +02:00
}
2019-02-01 23:46:58 +01:00
if ( bundleFileInfo && bundle . sourceFiles . length ) {
2019-02-05 00:22:23 +01:00
const end = writer . getTextPos ( ) ;
2019-02-22 22:03:46 +01:00
if ( recordBundleFileTextLikeSection ( end ) ) {
2019-02-05 00:22:23 +01:00
// Store prologues
const prologues = getPrologueDirectivesFromBundledSourceFiles ( bundle ) ;
2019-02-11 22:44:37 +01:00
if ( prologues ) {
if ( ! bundleFileInfo . sources ) bundleFileInfo . sources = { } ;
bundleFileInfo . sources . prologues = prologues ;
}
2019-02-05 00:22:23 +01:00
// Store helpes
const helpers = getHelpersFromBundledSourceFiles ( bundle ) ;
2019-02-11 22:44:37 +01:00
if ( helpers ) {
if ( ! bundleFileInfo . sources ) bundleFileInfo . sources = { } ;
bundleFileInfo . sources . helpers = helpers ;
}
2019-02-05 00:22:23 +01:00
}
2019-02-02 01:52:00 +01:00
}
2019-01-26 01:39:38 +01:00
2017-01-30 21:27:24 +01:00
reset ( ) ;
writer = previousWriter ;
}
2016-09-27 00:21:03 +02:00
2018-05-08 00:12:50 +02:00
function writeUnparsedSource ( unparsed : UnparsedSource , output : EmitTextWriter ) {
const previousWriter = writer ;
2018-09-05 02:50:06 +02:00
setWriter ( output , /*_sourceMapGenerator*/ undefined ) ;
2018-05-08 00:12:50 +02:00
print ( EmitHint . Unspecified , unparsed , /*sourceFile*/ undefined ) ;
reset ( ) ;
writer = previousWriter ;
}
2018-09-05 02:50:06 +02:00
function writeFile ( sourceFile : SourceFile , output : EmitTextWriter , sourceMapGenerator : SourceMapGenerator | undefined ) {
2018-03-31 02:43:37 +02:00
isOwnFileEmit = true ;
2017-01-30 21:27:24 +01:00
const previousWriter = writer ;
2018-09-05 02:50:06 +02:00
setWriter ( output , sourceMapGenerator ) ;
2017-02-24 00:27:22 +01:00
emitShebangIfNeeded ( sourceFile ) ;
2017-02-24 20:37:34 +01:00
emitPrologueDirectivesIfNeeded ( sourceFile ) ;
2017-01-30 21:27:24 +01:00
print ( EmitHint . SourceFile , sourceFile , sourceFile ) ;
reset ( ) ;
writer = previousWriter ;
2016-07-21 03:43:41 +02:00
}
2017-01-30 21:27:24 +01:00
function beginPrint() {
return ownWriter || ( ownWriter = createTextWriter ( newLine ) ) ;
}
function endPrint() {
2017-01-30 22:40:42 +01:00
const text = ownWriter . getText ( ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
ownWriter . clear ( ) ;
2017-01-30 21:27:24 +01:00
return text ;
}
2017-03-30 23:14:15 +02:00
function print ( hint : EmitHint , node : Node , sourceFile : SourceFile | undefined ) {
if ( sourceFile ) {
setSourceFile ( sourceFile ) ;
}
2018-05-04 01:04:52 +02:00
2021-04-19 18:34:46 +02:00
pipelineEmit ( hint , node , /*parenthesizerRule*/ undefined ) ;
2017-01-30 21:27:24 +01:00
}
2018-11-10 02:18:34 +01:00
function setSourceFile ( sourceFile : SourceFile | undefined ) {
2017-01-30 21:27:24 +01:00
currentSourceFile = sourceFile ;
2018-09-05 02:50:06 +02:00
currentLineMap = undefined ;
detachedCommentsInfo = undefined ;
2018-11-10 02:18:34 +01:00
if ( sourceFile ) {
setSourceMapSource ( sourceFile ) ;
}
2017-01-30 21:27:24 +01:00
}
2016-09-27 00:21:03 +02:00
2018-09-05 02:50:06 +02:00
function setWriter ( _writer : EmitTextWriter | undefined , _sourceMapGenerator : SourceMapGenerator | undefined ) {
if ( _writer && printerOptions . omitTrailingSemicolon ) {
2019-08-29 01:28:31 +02:00
_writer = getTrailingSemicolonDeferringWriter ( _writer ) ;
2018-08-22 21:42:36 +02:00
}
2018-09-05 02:50:06 +02:00
writer = _writer ! ; // TODO: GH#18217
sourceMapGenerator = _sourceMapGenerator ;
sourceMapsDisabled = ! writer || ! sourceMapGenerator ;
2016-07-21 03:43:41 +02:00
}
2017-01-30 21:27:24 +01:00
function reset() {
nodeIdToGeneratedName = [ ] ;
autoGeneratedIdToGeneratedName = [ ] ;
2020-06-26 19:12:47 +02:00
generatedNames = new Set ( ) ;
2017-01-30 21:27:24 +01:00
tempFlagsStack = [ ] ;
tempFlags = TempFlags . Auto ;
2018-01-16 21:33:55 +01:00
reservedNamesStack = [ ] ;
2021-03-25 22:46:16 +01:00
currentSourceFile = undefined ;
currentLineMap = undefined ;
2018-09-05 02:50:06 +02:00
detachedCommentsInfo = undefined ;
setWriter ( /*output*/ undefined , /*_sourceMapGenerator*/ undefined ) ;
}
function getCurrentLineMap() {
2018-11-10 02:18:34 +01:00
return currentLineMap || ( currentLineMap = getLineStarts ( currentSourceFile ! ) ) ;
2016-06-07 19:32:03 +02:00
}
2015-02-18 21:10:00 +01:00
2021-04-19 18:34:46 +02:00
function emit ( node : Node , parenthesizerRule ? : ( node : Node ) = > Node ) : void ;
function emit ( node : Node | undefined , parenthesizerRule ? : ( node : Node ) = > Node ) : void ;
function emit ( node : Node | undefined , parenthesizerRule ? : ( node : Node ) = > Node ) {
2018-09-07 23:11:54 +02:00
if ( node === undefined ) return ;
2019-02-22 22:51:13 +01:00
const prevSourceFileTextKind = recordBundleFileInternalSectionStart ( node ) ;
2021-04-19 18:34:46 +02:00
pipelineEmit ( EmitHint . Unspecified , node , parenthesizerRule ) ;
recordBundleFileInternalSectionEnd ( prevSourceFileTextKind ) ;
}
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
function emitIdentifierName ( node : Identifier ) : void ;
function emitIdentifierName ( node : Identifier | undefined ) : void ;
function emitIdentifierName ( node : Identifier | undefined ) {
if ( node === undefined ) return ;
pipelineEmit ( EmitHint . IdentifierName , node , /*parenthesizerRule*/ undefined ) ;
}
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
function emitExpression ( node : Expression , parenthesizerRule ? : ( node : Expression ) = > Expression ) : void ;
function emitExpression ( node : Expression | undefined , parenthesizerRule ? : ( node : Expression ) = > Expression ) : void ;
function emitExpression ( node : Expression | undefined , parenthesizerRule ? : ( node : Expression ) = > Expression ) {
if ( node === undefined ) return ;
pipelineEmit ( EmitHint . Expression , node , parenthesizerRule ) ;
}
function emitJsxAttributeValue ( node : StringLiteral | JsxExpression ) : void {
pipelineEmit ( isStringLiteral ( node ) ? EmitHint.JsxAttributeValue : EmitHint.Unspecified , node ) ;
}
function beforeEmitNode ( node : Node ) {
if ( preserveSourceNewlines && ( getEmitFlags ( node ) & EmitFlags . IgnoreSourceNewlines ) ) {
preserveSourceNewlines = false ;
}
}
function afterEmitNode ( savedPreserveSourceNewlines : boolean | undefined ) {
preserveSourceNewlines = savedPreserveSourceNewlines ;
}
function pipelineEmit ( emitHint : EmitHint , node : Node , parenthesizerRule ? : ( node : Node ) = > Node ) {
currentParenthesizerRule = parenthesizerRule ;
const pipelinePhase = getPipelinePhase ( PipelinePhase . Notification , emitHint , node ) ;
pipelinePhase ( emitHint , node ) ;
currentParenthesizerRule = undefined ;
2017-09-07 23:30:19 +02:00
}
2021-02-26 08:01:41 +01:00
function shouldEmitComments ( node : Node ) {
return ! commentsDisabled && ! isSourceFile ( node ) ;
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
function shouldEmitSourceMaps ( node : Node ) {
return ! sourceMapsDisabled &&
! isSourceFile ( node ) &&
! isInJsonFile ( node ) &&
! isUnparsedSource ( node ) &&
! isUnparsedPrepend ( node ) ;
2019-09-30 21:33:28 +02:00
}
2021-04-19 18:34:46 +02:00
function getPipelinePhase ( phase : PipelinePhase , emitHint : EmitHint , node : Node ) {
switch ( phase ) {
case PipelinePhase . Notification :
if ( onEmitNode !== noEmitNotification && ( ! isEmitNotificationEnabled || isEmitNotificationEnabled ( node ) ) ) {
return pipelineEmitWithNotification ;
2021-02-26 08:01:41 +01:00
}
2021-04-19 18:34:46 +02:00
// falls through
case PipelinePhase . Substitution :
if ( substituteNode !== noEmitSubstitution && ( lastSubstitution = substituteNode ( emitHint , node ) || node ) !== node ) {
if ( currentParenthesizerRule ) {
lastSubstitution = currentParenthesizerRule ( lastSubstitution ) ;
}
return pipelineEmitWithSubstitution ;
2021-02-26 08:01:41 +01:00
}
2021-04-19 18:34:46 +02:00
// falls through
case PipelinePhase . Comments :
if ( shouldEmitComments ( node ) ) {
return pipelineEmitWithComments ;
2021-02-26 08:01:41 +01:00
}
2021-04-19 18:34:46 +02:00
// falls through
case PipelinePhase . SourceMaps :
if ( shouldEmitSourceMaps ( node ) ) {
return pipelineEmitWithSourceMaps ;
}
// falls through
case PipelinePhase . Emit :
return pipelineEmitWithHint ;
default :
return Debug . assertNever ( phase ) ;
2021-02-26 08:01:41 +01:00
}
}
2021-04-19 18:34:46 +02:00
function getNextPipelinePhase ( currentPhase : PipelinePhase , emitHint : EmitHint , node : Node ) {
return getPipelinePhase ( currentPhase + 1 , emitHint , node ) ;
}
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
function pipelineEmitWithNotification ( hint : EmitHint , node : Node ) {
const pipelinePhase = getNextPipelinePhase ( PipelinePhase . Notification , hint , node ) ;
onEmitNode ( hint , node , pipelinePhase ) ;
}
2019-09-30 21:33:28 +02:00
2021-04-19 18:34:46 +02:00
function pipelineEmitWithHint ( hint : EmitHint , node : Node ) : void {
onBeforeEmitNode ? . ( node ) ;
if ( preserveSourceNewlines ) {
const savedPreserveSourceNewlines = preserveSourceNewlines ;
beforeEmitNode ( node ) ;
pipelineEmitWithHintWorker ( hint , node ) ;
afterEmitNode ( savedPreserveSourceNewlines ) ;
}
else {
pipelineEmitWithHintWorker ( hint , node ) ;
2021-02-26 08:01:41 +01:00
}
onAfterEmitNode ? . ( node ) ;
2021-04-19 18:34:46 +02:00
// clear the parenthesizer rule as we ascend
currentParenthesizerRule = undefined ;
2021-02-26 08:01:41 +01:00
}
2019-09-30 21:33:28 +02:00
2021-04-19 18:34:46 +02:00
function pipelineEmitWithHintWorker ( hint : EmitHint , node : Node ) : void {
if ( hint === EmitHint . SourceFile ) return emitSourceFile ( cast ( node , isSourceFile ) ) ;
if ( hint === EmitHint . IdentifierName ) return emitIdentifier ( cast ( node , isIdentifier ) ) ;
if ( hint === EmitHint . JsxAttributeValue ) return emitLiteral ( cast ( node , isStringLiteral ) , /*jsxAttributeEscape*/ true ) ;
if ( hint === EmitHint . MappedTypeParameter ) return emitMappedTypeParameter ( cast ( node , isTypeParameterDeclaration ) ) ;
if ( hint === EmitHint . EmbeddedStatement ) {
Debug . assertNode ( node , isEmptyStatement ) ;
return emitEmptyStatement ( /*isEmbeddedStatement*/ true ) ;
}
if ( hint === EmitHint . Unspecified ) {
switch ( node . kind ) {
// Pseudo-literals
case SyntaxKind . TemplateHead :
case SyntaxKind . TemplateMiddle :
case SyntaxKind . TemplateTail :
2021-05-18 15:20:57 +02:00
return emitLiteral ( node as LiteralExpression , /*jsxAttributeEscape*/ false ) ;
2017-01-30 21:27:24 +01:00
2021-04-19 18:34:46 +02:00
// Identifiers
case SyntaxKind . Identifier :
2021-05-18 15:20:57 +02:00
return emitIdentifier ( node as Identifier ) ;
2017-01-30 21:27:24 +01:00
2021-04-19 18:34:46 +02:00
// PrivateIdentifiers
case SyntaxKind . PrivateIdentifier :
return emitPrivateIdentifier ( node as PrivateIdentifier ) ;
2018-09-07 23:11:54 +02:00
2021-04-19 18:34:46 +02:00
// Parse tree nodes
// Names
case SyntaxKind . QualifiedName :
2021-05-18 15:20:57 +02:00
return emitQualifiedName ( node as QualifiedName ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ComputedPropertyName :
2021-05-18 15:20:57 +02:00
return emitComputedPropertyName ( node as ComputedPropertyName ) ;
2014-08-22 23:40:47 +02:00
2021-04-19 18:34:46 +02:00
// Signature elements
case SyntaxKind . TypeParameter :
2021-05-18 15:20:57 +02:00
return emitTypeParameter ( node as TypeParameterDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . Parameter :
2021-05-18 15:20:57 +02:00
return emitParameter ( node as ParameterDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . Decorator :
2021-05-18 15:20:57 +02:00
return emitDecorator ( node as Decorator ) ;
2018-05-04 01:04:52 +02:00
2021-04-19 18:34:46 +02:00
// Type members
case SyntaxKind . PropertySignature :
2021-05-18 15:20:57 +02:00
return emitPropertySignature ( node as PropertySignature ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . PropertyDeclaration :
2021-05-18 15:20:57 +02:00
return emitPropertyDeclaration ( node as PropertyDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MethodSignature :
2021-05-18 15:20:57 +02:00
return emitMethodSignature ( node as MethodSignature ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MethodDeclaration :
2021-05-18 15:20:57 +02:00
return emitMethodDeclaration ( node as MethodDeclaration ) ;
2021-06-25 18:24:05 +02:00
case SyntaxKind . ClassStaticBlockDeclaration :
return emitClassStaticBlockDeclaration ( node as ClassStaticBlockDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . Constructor :
2021-05-18 15:20:57 +02:00
return emitConstructor ( node as ConstructorDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . GetAccessor :
case SyntaxKind . SetAccessor :
2021-05-18 15:20:57 +02:00
return emitAccessorDeclaration ( node as AccessorDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . CallSignature :
2021-05-18 15:20:57 +02:00
return emitCallSignature ( node as CallSignatureDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ConstructSignature :
2021-05-18 15:20:57 +02:00
return emitConstructSignature ( node as ConstructSignatureDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . IndexSignature :
2021-05-18 15:20:57 +02:00
return emitIndexSignature ( node as IndexSignatureDeclaration ) ;
2018-05-04 01:04:52 +02:00
2021-04-19 18:34:46 +02:00
// Types
case SyntaxKind . TypePredicate :
2021-05-18 15:20:57 +02:00
return emitTypePredicate ( node as TypePredicateNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeReference :
2021-05-18 15:20:57 +02:00
return emitTypeReference ( node as TypeReferenceNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . FunctionType :
2021-05-18 15:20:57 +02:00
return emitFunctionType ( node as FunctionTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ConstructorType :
2021-05-18 15:20:57 +02:00
return emitConstructorType ( node as ConstructorTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeQuery :
2021-05-18 15:20:57 +02:00
return emitTypeQuery ( node as TypeQueryNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeLiteral :
2021-05-18 15:20:57 +02:00
return emitTypeLiteral ( node as TypeLiteralNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ArrayType :
2021-05-18 15:20:57 +02:00
return emitArrayType ( node as ArrayTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TupleType :
2021-05-18 15:20:57 +02:00
return emitTupleType ( node as TupleTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . OptionalType :
2021-05-18 15:20:57 +02:00
return emitOptionalType ( node as OptionalTypeNode ) ;
2021-04-19 18:34:46 +02:00
// SyntaxKind.RestType is handled below
case SyntaxKind . UnionType :
2021-05-18 15:20:57 +02:00
return emitUnionType ( node as UnionTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . IntersectionType :
2021-05-18 15:20:57 +02:00
return emitIntersectionType ( node as IntersectionTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ConditionalType :
2021-05-18 15:20:57 +02:00
return emitConditionalType ( node as ConditionalTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . InferType :
2021-05-18 15:20:57 +02:00
return emitInferType ( node as InferTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ParenthesizedType :
2021-05-18 15:20:57 +02:00
return emitParenthesizedType ( node as ParenthesizedTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ExpressionWithTypeArguments :
2021-05-18 15:20:57 +02:00
return emitExpressionWithTypeArguments ( node as ExpressionWithTypeArguments ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ThisType :
return emitThisType ( ) ;
case SyntaxKind . TypeOperator :
2021-05-18 15:20:57 +02:00
return emitTypeOperator ( node as TypeOperatorNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . IndexedAccessType :
2021-05-18 15:20:57 +02:00
return emitIndexedAccessType ( node as IndexedAccessTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MappedType :
2021-05-18 15:20:57 +02:00
return emitMappedType ( node as MappedTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . LiteralType :
2021-05-18 15:20:57 +02:00
return emitLiteralType ( node as LiteralTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamedTupleMember :
return emitNamedTupleMember ( node as NamedTupleMember ) ;
case SyntaxKind . TemplateLiteralType :
2021-05-18 15:20:57 +02:00
return emitTemplateType ( node as TemplateLiteralTypeNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TemplateLiteralTypeSpan :
2021-05-18 15:20:57 +02:00
return emitTemplateTypeSpan ( node as TemplateLiteralTypeSpan ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ImportType :
2021-05-18 15:20:57 +02:00
return emitImportTypeNode ( node as ImportTypeNode ) ;
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
// Binding patterns
case SyntaxKind . ObjectBindingPattern :
2021-05-18 15:20:57 +02:00
return emitObjectBindingPattern ( node as ObjectBindingPattern ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ArrayBindingPattern :
2021-05-18 15:20:57 +02:00
return emitArrayBindingPattern ( node as ArrayBindingPattern ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . BindingElement :
2021-05-18 15:20:57 +02:00
return emitBindingElement ( node as BindingElement ) ;
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
// Misc
case SyntaxKind . TemplateSpan :
2021-05-18 15:20:57 +02:00
return emitTemplateSpan ( node as TemplateSpan ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . SemicolonClassElement :
return emitSemicolonClassElement ( ) ;
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
// Statements
case SyntaxKind . Block :
2021-05-18 15:20:57 +02:00
return emitBlock ( node as Block ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . VariableStatement :
2021-05-18 15:20:57 +02:00
return emitVariableStatement ( node as VariableStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . EmptyStatement :
return emitEmptyStatement ( /*isEmbeddedStatement*/ false ) ;
case SyntaxKind . ExpressionStatement :
2021-05-18 15:20:57 +02:00
return emitExpressionStatement ( node as ExpressionStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . IfStatement :
2021-05-18 15:20:57 +02:00
return emitIfStatement ( node as IfStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . DoStatement :
2021-05-18 15:20:57 +02:00
return emitDoStatement ( node as DoStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . WhileStatement :
2021-05-18 15:20:57 +02:00
return emitWhileStatement ( node as WhileStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ForStatement :
2021-05-18 15:20:57 +02:00
return emitForStatement ( node as ForStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ForInStatement :
2021-05-18 15:20:57 +02:00
return emitForInStatement ( node as ForInStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ForOfStatement :
2021-05-18 15:20:57 +02:00
return emitForOfStatement ( node as ForOfStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ContinueStatement :
2021-05-18 15:20:57 +02:00
return emitContinueStatement ( node as ContinueStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . BreakStatement :
2021-05-18 15:20:57 +02:00
return emitBreakStatement ( node as BreakStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ReturnStatement :
2021-05-18 15:20:57 +02:00
return emitReturnStatement ( node as ReturnStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . WithStatement :
2021-05-18 15:20:57 +02:00
return emitWithStatement ( node as WithStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . SwitchStatement :
2021-05-18 15:20:57 +02:00
return emitSwitchStatement ( node as SwitchStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . LabeledStatement :
2021-05-18 15:20:57 +02:00
return emitLabeledStatement ( node as LabeledStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ThrowStatement :
2021-05-18 15:20:57 +02:00
return emitThrowStatement ( node as ThrowStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TryStatement :
2021-05-18 15:20:57 +02:00
return emitTryStatement ( node as TryStatement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . DebuggerStatement :
2021-05-18 15:20:57 +02:00
return emitDebuggerStatement ( node as DebuggerStatement ) ;
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
// Declarations
case SyntaxKind . VariableDeclaration :
2021-05-18 15:20:57 +02:00
return emitVariableDeclaration ( node as VariableDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . VariableDeclarationList :
2021-05-18 15:20:57 +02:00
return emitVariableDeclarationList ( node as VariableDeclarationList ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . FunctionDeclaration :
2021-05-18 15:20:57 +02:00
return emitFunctionDeclaration ( node as FunctionDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ClassDeclaration :
2021-05-18 15:20:57 +02:00
return emitClassDeclaration ( node as ClassDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . InterfaceDeclaration :
2021-05-18 15:20:57 +02:00
return emitInterfaceDeclaration ( node as InterfaceDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeAliasDeclaration :
2021-05-18 15:20:57 +02:00
return emitTypeAliasDeclaration ( node as TypeAliasDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . EnumDeclaration :
2021-05-18 15:20:57 +02:00
return emitEnumDeclaration ( node as EnumDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ModuleDeclaration :
2021-05-18 15:20:57 +02:00
return emitModuleDeclaration ( node as ModuleDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ModuleBlock :
2021-05-18 15:20:57 +02:00
return emitModuleBlock ( node as ModuleBlock ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . CaseBlock :
2021-05-18 15:20:57 +02:00
return emitCaseBlock ( node as CaseBlock ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamespaceExportDeclaration :
2021-05-18 15:20:57 +02:00
return emitNamespaceExportDeclaration ( node as NamespaceExportDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ImportEqualsDeclaration :
2021-05-18 15:20:57 +02:00
return emitImportEqualsDeclaration ( node as ImportEqualsDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ImportDeclaration :
2021-05-18 15:20:57 +02:00
return emitImportDeclaration ( node as ImportDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ImportClause :
2021-05-18 15:20:57 +02:00
return emitImportClause ( node as ImportClause ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamespaceImport :
2021-05-18 15:20:57 +02:00
return emitNamespaceImport ( node as NamespaceImport ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamespaceExport :
2021-05-18 15:20:57 +02:00
return emitNamespaceExport ( node as NamespaceExport ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamedImports :
2021-05-18 15:20:57 +02:00
return emitNamedImports ( node as NamedImports ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ImportSpecifier :
2021-05-18 15:20:57 +02:00
return emitImportSpecifier ( node as ImportSpecifier ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ExportAssignment :
2021-05-18 15:20:57 +02:00
return emitExportAssignment ( node as ExportAssignment ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ExportDeclaration :
2021-05-18 15:20:57 +02:00
return emitExportDeclaration ( node as ExportDeclaration ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NamedExports :
2021-05-18 15:20:57 +02:00
return emitNamedExports ( node as NamedExports ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ExportSpecifier :
2021-05-18 15:20:57 +02:00
return emitExportSpecifier ( node as ExportSpecifier ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MissingDeclaration :
return ;
2021-02-26 08:01:41 +01:00
2021-04-19 18:34:46 +02:00
// Module references
case SyntaxKind . ExternalModuleReference :
2021-05-18 15:20:57 +02:00
return emitExternalModuleReference ( node as ExternalModuleReference ) ;
2016-09-26 20:20:24 +02:00
2021-04-19 18:34:46 +02:00
// JSX (non-expression)
case SyntaxKind . JsxText :
2021-05-18 15:20:57 +02:00
return emitJsxText ( node as JsxText ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxOpeningElement :
case SyntaxKind . JsxOpeningFragment :
2021-05-18 15:20:57 +02:00
return emitJsxOpeningElementOrFragment ( node as JsxOpeningElement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxClosingElement :
case SyntaxKind . JsxClosingFragment :
2021-05-18 15:20:57 +02:00
return emitJsxClosingElementOrFragment ( node as JsxClosingElement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxAttribute :
2021-05-18 15:20:57 +02:00
return emitJsxAttribute ( node as JsxAttribute ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxAttributes :
2021-05-18 15:20:57 +02:00
return emitJsxAttributes ( node as JsxAttributes ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxSpreadAttribute :
2021-05-18 15:20:57 +02:00
return emitJsxSpreadAttribute ( node as JsxSpreadAttribute ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxExpression :
2021-05-18 15:20:57 +02:00
return emitJsxExpression ( node as JsxExpression ) ;
2017-01-30 21:27:24 +01:00
2021-04-19 18:34:46 +02:00
// Clauses
case SyntaxKind . CaseClause :
2021-05-18 15:20:57 +02:00
return emitCaseClause ( node as CaseClause ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . DefaultClause :
2021-05-18 15:20:57 +02:00
return emitDefaultClause ( node as DefaultClause ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . HeritageClause :
2021-05-18 15:20:57 +02:00
return emitHeritageClause ( node as HeritageClause ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . CatchClause :
2021-05-18 15:20:57 +02:00
return emitCatchClause ( node as CatchClause ) ;
2021-04-19 18:34:46 +02:00
// Property assignments
case SyntaxKind . PropertyAssignment :
2021-05-18 15:20:57 +02:00
return emitPropertyAssignment ( node as PropertyAssignment ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ShorthandPropertyAssignment :
2021-05-18 15:20:57 +02:00
return emitShorthandPropertyAssignment ( node as ShorthandPropertyAssignment ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . SpreadAssignment :
return emitSpreadAssignment ( node as SpreadAssignment ) ;
// Enum
case SyntaxKind . EnumMember :
2021-05-18 15:20:57 +02:00
return emitEnumMember ( node as EnumMember ) ;
2021-04-19 18:34:46 +02:00
// Unparsed
case SyntaxKind . UnparsedPrologue :
2021-05-18 15:20:57 +02:00
return writeUnparsedNode ( node as UnparsedNode ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . UnparsedSource :
case SyntaxKind . UnparsedPrepend :
2021-05-18 15:20:57 +02:00
return emitUnparsedSourceOrPrepend ( node as UnparsedSource ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . UnparsedText :
case SyntaxKind . UnparsedInternalText :
2021-05-18 15:20:57 +02:00
return emitUnparsedTextLike ( node as UnparsedTextLike ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . UnparsedSyntheticReference :
2021-05-18 15:20:57 +02:00
return emitUnparsedSyntheticReference ( node as UnparsedSyntheticReference ) ;
2021-04-19 18:34:46 +02:00
// Top-level nodes
case SyntaxKind . SourceFile :
2021-05-18 15:20:57 +02:00
return emitSourceFile ( node as SourceFile ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . Bundle :
return Debug . fail ( "Bundles should be printed using printBundle" ) ;
// SyntaxKind.UnparsedSource (handled above)
case SyntaxKind . InputFiles :
return Debug . fail ( "InputFiles should not be printed" ) ;
// JSDoc nodes (only used in codefixes currently)
case SyntaxKind . JSDocTypeExpression :
return emitJSDocTypeExpression ( node as JSDocTypeExpression ) ;
case SyntaxKind . JSDocNameReference :
return emitJSDocNameReference ( node as JSDocNameReference ) ;
case SyntaxKind . JSDocAllType :
return writePunctuation ( "*" ) ;
case SyntaxKind . JSDocUnknownType :
return writePunctuation ( "?" ) ;
case SyntaxKind . JSDocNullableType :
return emitJSDocNullableType ( node as JSDocNullableType ) ;
case SyntaxKind . JSDocNonNullableType :
return emitJSDocNonNullableType ( node as JSDocNonNullableType ) ;
case SyntaxKind . JSDocOptionalType :
return emitJSDocOptionalType ( node as JSDocOptionalType ) ;
case SyntaxKind . JSDocFunctionType :
return emitJSDocFunctionType ( node as JSDocFunctionType ) ;
case SyntaxKind . RestType :
case SyntaxKind . JSDocVariadicType :
return emitRestOrJSDocVariadicType ( node as RestTypeNode | JSDocVariadicType ) ;
case SyntaxKind . JSDocNamepathType :
return ;
case SyntaxKind . JSDocComment :
return emitJSDoc ( node as JSDoc ) ;
case SyntaxKind . JSDocTypeLiteral :
return emitJSDocTypeLiteral ( node as JSDocTypeLiteral ) ;
case SyntaxKind . JSDocSignature :
return emitJSDocSignature ( node as JSDocSignature ) ;
case SyntaxKind . JSDocTag :
case SyntaxKind . JSDocClassTag :
return emitJSDocSimpleTag ( node as JSDocTag ) ;
case SyntaxKind . JSDocAugmentsTag :
case SyntaxKind . JSDocImplementsTag :
return emitJSDocHeritageTag ( node as JSDocImplementsTag | JSDocAugmentsTag ) ;
case SyntaxKind . JSDocAuthorTag :
case SyntaxKind . JSDocDeprecatedTag :
return ;
// SyntaxKind.JSDocClassTag (see JSDocTag, above)
case SyntaxKind . JSDocPublicTag :
case SyntaxKind . JSDocPrivateTag :
case SyntaxKind . JSDocProtectedTag :
case SyntaxKind . JSDocReadonlyTag :
case SyntaxKind . JSDocOverrideTag :
return ;
case SyntaxKind . JSDocCallbackTag :
return emitJSDocCallbackTag ( node as JSDocCallbackTag ) ;
// SyntaxKind.JSDocEnumTag (see below)
case SyntaxKind . JSDocParameterTag :
case SyntaxKind . JSDocPropertyTag :
return emitJSDocPropertyLikeTag ( node as JSDocPropertyLikeTag ) ;
case SyntaxKind . JSDocEnumTag :
case SyntaxKind . JSDocReturnTag :
case SyntaxKind . JSDocThisTag :
case SyntaxKind . JSDocTypeTag :
return emitJSDocSimpleTypedTag ( node as JSDocTypeTag ) ;
case SyntaxKind . JSDocTemplateTag :
return emitJSDocTemplateTag ( node as JSDocTemplateTag ) ;
case SyntaxKind . JSDocTypedefTag :
return emitJSDocTypedefTag ( node as JSDocTypedefTag ) ;
case SyntaxKind . JSDocSeeTag :
return emitJSDocSeeTag ( node as JSDocSeeTag ) ;
// SyntaxKind.JSDocPropertyTag (see JSDocParameterTag, above)
// Transformation nodes
case SyntaxKind . NotEmittedStatement :
case SyntaxKind . EndOfDeclarationMarker :
case SyntaxKind . MergeDeclarationMarker :
return ;
}
if ( isExpression ( node ) ) {
hint = EmitHint . Expression ;
if ( substituteNode !== noEmitSubstitution ) {
const substitute = substituteNode ( hint , node ) || node ;
if ( substitute !== node ) {
node = substitute ;
if ( currentParenthesizerRule ) {
node = currentParenthesizerRule ( node ) ;
}
}
}
}
}
if ( hint === EmitHint . Expression ) {
switch ( node . kind ) {
// Literals
case SyntaxKind . NumericLiteral :
case SyntaxKind . BigIntLiteral :
2021-05-18 15:20:57 +02:00
return emitNumericOrBigIntLiteral ( node as NumericLiteral | BigIntLiteral ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . StringLiteral :
case SyntaxKind . RegularExpressionLiteral :
case SyntaxKind . NoSubstitutionTemplateLiteral :
2021-05-18 15:20:57 +02:00
return emitLiteral ( node as LiteralExpression , /*jsxAttributeEscape*/ false ) ;
2021-04-19 18:34:46 +02:00
// Identifiers
case SyntaxKind . Identifier :
2021-05-18 15:20:57 +02:00
return emitIdentifier ( node as Identifier ) ;
2021-04-19 18:34:46 +02:00
// Expressions
case SyntaxKind . ArrayLiteralExpression :
2021-05-18 15:20:57 +02:00
return emitArrayLiteralExpression ( node as ArrayLiteralExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ObjectLiteralExpression :
2021-05-18 15:20:57 +02:00
return emitObjectLiteralExpression ( node as ObjectLiteralExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . PropertyAccessExpression :
2021-05-18 15:20:57 +02:00
return emitPropertyAccessExpression ( node as PropertyAccessExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ElementAccessExpression :
2021-05-18 15:20:57 +02:00
return emitElementAccessExpression ( node as ElementAccessExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . CallExpression :
2021-05-18 15:20:57 +02:00
return emitCallExpression ( node as CallExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NewExpression :
2021-05-18 15:20:57 +02:00
return emitNewExpression ( node as NewExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TaggedTemplateExpression :
2021-05-18 15:20:57 +02:00
return emitTaggedTemplateExpression ( node as TaggedTemplateExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeAssertionExpression :
2021-05-18 15:20:57 +02:00
return emitTypeAssertionExpression ( node as TypeAssertion ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ParenthesizedExpression :
2021-05-18 15:20:57 +02:00
return emitParenthesizedExpression ( node as ParenthesizedExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . FunctionExpression :
2021-05-18 15:20:57 +02:00
return emitFunctionExpression ( node as FunctionExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ArrowFunction :
2021-05-18 15:20:57 +02:00
return emitArrowFunction ( node as ArrowFunction ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . DeleteExpression :
2021-05-18 15:20:57 +02:00
return emitDeleteExpression ( node as DeleteExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TypeOfExpression :
2021-05-18 15:20:57 +02:00
return emitTypeOfExpression ( node as TypeOfExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . VoidExpression :
2021-05-18 15:20:57 +02:00
return emitVoidExpression ( node as VoidExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . AwaitExpression :
2021-05-18 15:20:57 +02:00
return emitAwaitExpression ( node as AwaitExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . PrefixUnaryExpression :
2021-05-18 15:20:57 +02:00
return emitPrefixUnaryExpression ( node as PrefixUnaryExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . PostfixUnaryExpression :
2021-05-18 15:20:57 +02:00
return emitPostfixUnaryExpression ( node as PostfixUnaryExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . BinaryExpression :
2021-05-18 15:20:57 +02:00
return emitBinaryExpression ( node as BinaryExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ConditionalExpression :
2021-05-18 15:20:57 +02:00
return emitConditionalExpression ( node as ConditionalExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . TemplateExpression :
2021-05-18 15:20:57 +02:00
return emitTemplateExpression ( node as TemplateExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . YieldExpression :
2021-05-18 15:20:57 +02:00
return emitYieldExpression ( node as YieldExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . SpreadElement :
2021-05-18 15:20:57 +02:00
return emitSpreadElement ( node as SpreadElement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . ClassExpression :
2021-05-18 15:20:57 +02:00
return emitClassExpression ( node as ClassExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . OmittedExpression :
return ;
case SyntaxKind . AsExpression :
2021-05-18 15:20:57 +02:00
return emitAsExpression ( node as AsExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . NonNullExpression :
2021-05-18 15:20:57 +02:00
return emitNonNullExpression ( node as NonNullExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MetaProperty :
2021-05-18 15:20:57 +02:00
return emitMetaProperty ( node as MetaProperty ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . SyntheticExpression :
return Debug . fail ( "SyntheticExpression should never be printed." ) ;
// JSX
case SyntaxKind . JsxElement :
2021-05-18 15:20:57 +02:00
return emitJsxElement ( node as JsxElement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxSelfClosingElement :
2021-05-18 15:20:57 +02:00
return emitJsxSelfClosingElement ( node as JsxSelfClosingElement ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . JsxFragment :
2021-05-18 15:20:57 +02:00
return emitJsxFragment ( node as JsxFragment ) ;
2021-04-19 18:34:46 +02:00
// Synthesized list
case SyntaxKind . SyntaxList :
return Debug . fail ( "SyntaxList should not be printed" ) ;
// Transformation nodes
case SyntaxKind . NotEmittedStatement :
return ;
case SyntaxKind . PartiallyEmittedExpression :
2021-05-18 15:20:57 +02:00
return emitPartiallyEmittedExpression ( node as PartiallyEmittedExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . CommaListExpression :
2021-05-18 15:20:57 +02:00
return emitCommaList ( node as CommaListExpression ) ;
2021-04-19 18:34:46 +02:00
case SyntaxKind . MergeDeclarationMarker :
case SyntaxKind . EndOfDeclarationMarker :
return ;
case SyntaxKind . SyntheticReferenceExpression :
return Debug . fail ( "SyntheticReferenceExpression should not be printed" ) ;
}
}
if ( isKeyword ( node . kind ) ) return writeTokenNode ( node , writeKeyword ) ;
if ( isTokenKind ( node . kind ) ) return writeTokenNode ( node , writePunctuation ) ;
Debug . fail ( ` Unhandled SyntaxKind: ${ Debug . formatSyntaxKind ( node . kind ) } . ` ) ;
}
function emitMappedTypeParameter ( node : TypeParameterDeclaration ) : void {
emit ( node . name ) ;
writeSpace ( ) ;
writeKeyword ( "in" ) ;
writeSpace ( ) ;
emit ( node . constraint ) ;
}
function pipelineEmitWithSubstitution ( hint : EmitHint , node : Node ) {
const pipelinePhase = getNextPipelinePhase ( PipelinePhase . Substitution , hint , node ) ;
Debug . assertIsDefined ( lastSubstitution ) ;
node = lastSubstitution ;
lastSubstitution = undefined ;
pipelinePhase ( hint , node ) ;
}
function getHelpersFromBundledSourceFiles ( bundle : Bundle ) : string [ ] | undefined {
let result : string [ ] | undefined ;
if ( module Kind === ModuleKind . None || printerOptions . noEmitHelpers ) {
return undefined ;
}
const bundledHelpers = new Map < string , boolean > ( ) ;
for ( const sourceFile of bundle . sourceFiles ) {
const shouldSkip = getExternalHelpersModuleName ( sourceFile ) !== undefined ;
const helpers = getSortedEmitHelpers ( sourceFile ) ;
if ( ! helpers ) continue ;
for ( const helper of helpers ) {
if ( ! helper . scoped && ! shouldSkip && ! bundledHelpers . get ( helper . name ) ) {
bundledHelpers . set ( helper . name , true ) ;
( result || ( result = [ ] ) ) . push ( helper . name ) ;
}
}
}
2021-02-26 08:01:41 +01:00
return result ;
2017-09-07 23:30:19 +02:00
}
2021-02-26 08:01:41 +01:00
function emitHelpers ( node : Node ) {
let helpersEmitted = false ;
2021-05-18 15:20:57 +02:00
const bundle = node . kind === SyntaxKind . Bundle ? node as Bundle : undefined ;
2021-02-26 08:01:41 +01:00
if ( bundle && module Kind === ModuleKind . None ) {
return ;
2018-08-22 21:42:36 +02:00
}
2021-02-26 08:01:41 +01:00
const numPrepends = bundle ? bundle.prepends.length : 0 ;
const numNodes = bundle ? bundle . sourceFiles . length + numPrepends : 1 ;
for ( let i = 0 ; i < numNodes ; i ++ ) {
const currentNode = bundle ? i < numPrepends ? bundle . prepends [ i ] : bundle . sourceFiles [ i - numPrepends ] : node ;
const sourceFile = isSourceFile ( currentNode ) ? currentNode : isUnparsedSource ( currentNode ) ? undefined : currentSourceFile ! ;
const shouldSkip = printerOptions . noEmitHelpers || ( ! ! sourceFile && hasRecordedExternalHelpers ( sourceFile ) ) ;
const shouldBundle = ( isSourceFile ( currentNode ) || isUnparsedSource ( currentNode ) ) && ! isOwnFileEmit ;
const helpers = isUnparsedSource ( currentNode ) ? currentNode.helpers : getSortedEmitHelpers ( currentNode ) ;
if ( helpers ) {
for ( const helper of helpers ) {
if ( ! helper . scoped ) {
// Skip the helper if it can be skipped and the noEmitHelpers compiler
// option is set, or if it can be imported and the importHelpers compiler
// option is set.
if ( shouldSkip ) continue ;
2018-05-04 01:04:52 +02:00
2021-02-26 08:01:41 +01:00
// Skip the helper if it can be bundled but hasn't already been emitted and we
// are emitting a bundled module.
if ( shouldBundle ) {
if ( bundledHelpers . get ( helper . name ) ) {
continue ;
}
2018-05-08 00:12:50 +02:00
2021-02-26 08:01:41 +01:00
bundledHelpers . set ( helper . name , true ) ;
}
}
else if ( bundle ) {
// Skip the helper if it is scoped and we are emitting bundled helpers
continue ;
}
const pos = getTextPosWithWriteLine ( ) ;
if ( typeof helper . text === "string" ) {
writeLines ( helper . text ) ;
}
else {
writeLines ( helper . text ( makeFileLevelOptimisticUniqueName ) ) ;
}
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.EmitHelpers , data : helper.name } ) ;
helpersEmitted = true ;
}
}
}
2019-02-15 18:46:37 +01:00
2021-02-26 08:01:41 +01:00
return helpersEmitted ;
}
2019-01-17 21:11:51 +01:00
2021-02-26 08:01:41 +01:00
function getSortedEmitHelpers ( node : Node ) {
const helpers = getEmitHelpers ( node ) ;
return helpers && stableSort ( helpers , compareEmitHelpers ) ;
}
2019-02-02 05:10:31 +01:00
2021-02-26 08:01:41 +01:00
//
// Literals/Pseudo-literals
//
2019-02-02 05:10:31 +01:00
2021-02-26 08:01:41 +01:00
// SyntaxKind.NumericLiteral
// SyntaxKind.BigIntLiteral
function emitNumericOrBigIntLiteral ( node : NumericLiteral | BigIntLiteral ) {
emitLiteral ( node , /*jsxAttributeEscape*/ false ) ;
}
2018-05-04 01:04:52 +02:00
2021-02-26 08:01:41 +01:00
// SyntaxKind.StringLiteral
// SyntaxKind.RegularExpressionLiteral
// SyntaxKind.NoSubstitutionTemplateLiteral
// SyntaxKind.TemplateHead
// SyntaxKind.TemplateMiddle
// SyntaxKind.TemplateTail
function emitLiteral ( node : LiteralLikeNode , jsxAttributeEscape : boolean ) {
const text = getLiteralTextOfNode ( node , printerOptions . neverAsciiEscape , jsxAttributeEscape ) ;
if ( ( printerOptions . sourceMap || printerOptions . inlineSourceMap )
&& ( node . kind === SyntaxKind . StringLiteral || isTemplateLiteralKind ( node . kind ) ) ) {
writeLiteral ( text ) ;
}
else {
// Quick info expects all literals to be called with writeStringLiteral, as there's no specific type for numberLiterals
writeStringLiteral ( text ) ;
}
}
Private named instance fields (#30829)
* Fix display of private names in language server
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Parse private names
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* update parser error recovery tests to use ¬ not #
The intent of the tests seemed to be to
regiment the behavior of the parser
when a weird symbol is encountered.
The `#` is now taken by private identifiers,
so `¬` seems like a good new choice for
keeping the diff small, since it also fits in
16 bits (wide emojis would be treated
as multiple characters, since the scanner
uses ++).
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Private Name Support in the Checker (#5)
- [x] treat private names as unique:
- case 1: cannot say that a variable is of a class type unless the variable points to an instance of the class
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesUnique.ts)
- case 2: private names in class hierarchies do not conflict
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoConflictWhenInheriting.ts)
- [x] `#constructor` is reserved
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts)
- check in `bindWorker`, where every node is visited
- [x] Accessibility modifiers can't be used with private names
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoAccessibilityModifiers.ts)
- implemented in `checkAccessibilityModifiers`, using `ModifierFlags.AccessibilityModifier`
- [x] `delete #foo` not allowed
- [x] Private name accesses not allowed outside of the defining class
- see test: https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameNotAccessibleOutsideDefiningClass.ts
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts)
- implemented in `checkDeleteExpression`
- [x] Do [the right thing](https://gist.github.com/mheiber/b6fc7adb426c2e1cdaceb5d7786fc630) for nested classes
mv private name tests together
more checker tests for private names
update naming and cleanup for check private names
for private name support in the checker:
- make names more consistent
- remove unnecessary checks
- add utility function to public API
- other small cleanup
Move getPropertyNameForUniqueESSymbol to utility
for consistency with other calculation of
special property names (starting with __),
move the calculation of property names for
unique es symbols to `utilities.ts`.
private name tests strict+es6
Update private name tests to use 'strict'
type checking and to target es6 instead of
default. Makes the js output easier to read
and tests more surface area with other
checker features.
error message for private names in obj literals
Disallow decorating private-named properties
because the spec is still in flux.
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Add private instance field transformation, pr feedback
Implements private instance fields on top of the class properties refactor.
This commit also includes incorporation of PR feedback on the
checker, parser, and transformer in order to make the rebase
manageable.
Co-Authored-By: Max Heiber <max.heiber@gmail.com>
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
Signed-off-by: Joey Watts <jwatts43@bloomberg.net>
Signed-off-by: Max Heiber <max.heiber@gmail.com>
Incorporate PR feedback
Fix checker crash with new block scoped bindings
Add classExpressionInLoop test
Update baselines for private name errors
Apply suggestions from code review
Fix privateNameFieldCallExpression test
Remove unnecessary comment
Fix PropertyAccessEntityNameExpression type
Remove PrivateName from PropertyNameLiteral
Add createPrivateName
Remove PrivateName type from textSourceNode
Add Debug asserts for invalid syntax kinds
Don't output private name syntax when undeclared
Make PrivateName extend Node
Update baselines for public API
Fix completions in language server
Fix fourslash test crash
intern private name descriptions
undo expensive node.name.parent assignment
Back the way things were on `master`: only
assign node.name.parent when we need to
Add tests for private names and JSDoc
Patch hoverOverPrivateName fourslash test
Fix goToDefinition for private-named fields
remove Debug.fail for private name outside class
Remove Debug.fail in binder.ts::`getDeclarationName`.
It turns out this code path *does* get hit (intentionally).
For best error messages, return `undefined` and rely
on the parser generating a good error message
"Private names are not allowed outside class bodies"
Add rbuckton test cases for private names
These test cases specifically exercise where
we needed to use name-mangling. They are
cases where private names have the same
description.
- private names no conflict when inheriting
- private names distinct even when
the two classes have the same name
check dup instance+static private identifiers
class A {
#foo;
static #foo;
}
not allowed because static and private names
share the same lexical scope
https://tc39.es/proposal-class-fields/#prod-ClassBody
refactor getPropertyForPrivateName, rel spans
refactor getPropertyForPrivateName so
it is easier to read (use findAncestor instead
of loop).
Fix bugs in getPropertyForPrivateName:
- make it work with deeply-nested classes with
and without shadowing
- make it catch shadowing when the conflict is
between static and instance
private name descriptions (these can actually
clash)
And add related spans to diagnostics
for getPropertyForPrivateName
catch conflicts between static and instance
private identifiers:
- cannot have an instance and static private identifier
with the same spelling, as there is only one namespace
for private names
rename 'PrivateName' to 'PrivateIdentifier'
to match the change of wording in the spec
prposal:
https://tc39.es/proposal-class-fields/#sec-syntax
The rename in the spec was to avoid confusion
between the AST Node PrivateIdentifier
and the internal spec type PrivateName.
So one uses the [[Description]] of a
PrivateIdentifier to look up the PrivateName
for a given scope.
This corresponds closely to our implementation
in the binder and checker:
- we mangle PrivateIdentifier.escapedText to
get a `key` which we use to get the symbol
for a property
f
getLiteralTypeFromProperty-check privateIdentifier
rename and simplify privateNameAndAny test case
make it clearer that all this test is showing is
that we allow accessing arbitrary private identifiers
on `any`.
Note: we could have something more sound here by
checking that there is a private-named field declaration
in a class scope above the property access.
Discussion:
https://github.com/microsoft/TypeScript/pull/30829/files#r302760015
Fix typo in checker
s/identifer/identifier
remove accidental change
patch fourslash test broken by isPrivateIdentifier
just needed to add a check to see if the symbol
.name is defined
extract reportUnmatchedProperty
per @nsandersn feedback
propertiesRelatedTo was getting to long
pull out the unmatchedProperty reporting into
a seprate function
fix typo in private names test
Fix type soundness with private names
Remove PrivateIdentifier from emit with Expr hint
Fixup helpers and set function name for privates
remove accidentally-committed baselines
These baselines somehow ended up in this pr,
though they have nothing to do with the changes
Revert "getLiteralTypeFromProperty-check privateIdentifier"
This reverts commit bd1155c300bc3517a0543580f4790268f86e473f.
reason: the check for isIdentifier in
getLiteralTypeFromProperty is superfluous because
we do this check in getLiteralTypeFromPropertyName
Update comment in private name uniqueness test 3
I think the comments were not accurate and that we
export the error on `this.#x = child.#x` because:
- private names are lexically scoped: the code in question is not in a
lexical scope under the definition of Child's #x.
- private names are private to their containing class: never inherited
This expected behavior matches that of Chrome Canary and
my understanding of the spec
test private names use before def, circular ref
test private names use before def, circular ref
update diagnosticMessages s/delete/'delete'
per @DanielRosenwasser and @sandersn guidance,
use this style in diagnostic messages:
"operand of a 'delete' operator" (single quotes)
rather than old style:
"operand of a delete operator" (single quotes)
This is for consistency, as we use the new
style in the privateIdentifiers error messages
and it is consistent with our messages about
other operators
incorporate private names early exit feedback
and code style change to use a ternary
instead of if so we can 'const'
require private-named fields to be declared in JS
All fields must be declared in TS files.
In JS files, we typically do not have this requirement.
So special-case private fields, which must always
be declared (even in JS files, per spec)
update debug failure for es2015 private identifier
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
fix checker handling of private name in subclasse
update checker and tests to account for the
following ts features:
- private names do not participate in
the prototype chain, but *are* assigned
in the parent class' constructor. So
parent can access its *own* private fields
on instances of the subclass
Add more tests for private-named fields in JS
add test to hit symbolToExpression w private names
symbolToExpression knows about private names
add a test to exercise this code path
ban private-named static methods (not supported yet)
ban private-named methods (not supported yet)
ban private-named accessors (not supported yet)
fix privateIdentifier fourslash test
change assertion throw to return
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
Update comment in checker.ts re reserved members
Remove case for privateIdentifier in EntityNameExpr
Remove case for privateIdentifier in
EntityNameExpr. That code path is never hit,
and privateIdnetifiers cannot be entity names.
remove unnecessary parentheses
Ban private identifier in enum
As the new test, 'privateNameEnumNoEmit',
shows, the checker now correctly makes
a diagnostic for private identifiers in enums.
However, when noEmit is false we
hit this assertion in the transformer.
This assertion will have to be removed
so that we have a diagnostic here instead
of an assertion error.
When the assertion is removed,
the 'privateNameEnum' baseline
will have to be updated
Fix destructuring assignment, use createCallBinding, remove unneeded helper
Add class private field helpers to external helpers
Remove private identifier enum assertion, use missing identifiers
Fix hash map inefficiency by only using get
Update baselines with empty identifier change
Add privateNameEnum test baselines
Fix private identifier destructuring (array assignment defaults, unique names)
Use createPrivateIdentifierAssignment in destructuring transform
Fix lint error
Separate destructuring target visitor from regular visitor
Fix destructuring assignment with this bindings
Fix destructuring assignment with this bindings
Fix syntax error with destructuring assignment output
Disallow private identifiers in property signatures
remove duplicate test baselines
Add tests for undeclarated private identifiers
remove unnecessary cast
Nicer error message for mis-placed hashbang
Workaround v8 bug with destructured assignments
Optimize private identifier stack lookup
Avoid the cost of performing an array lookup to look at the top of the
private identifier environment stack.
Change function name to be more specific
Changes "getOperatorForCompoundAssignment" to
"getNonAssignmentOperatorForCompoundAssignment" now that this
function is accessible to the entire compiler.
Improve test case for private name assignment
Adds a compound assignment test case for a class with private names
being declared on the left-hand-side of the assignment expression.
Remove extra non-private-field test
Remove isPrivateIdentifierAssignmentExpression helper
Don't transform private names in ESNext target
Preserve private fields initialized to functions
Move function expressions to outer scope for efficiency
Add WeakMap collision check
Modify potential WeakMap collision condition
Fix this property assignment binding with private names
Add correct error message for WeakMap collision
Add error for statements before super with private identifiers
Refactor getPropertyForPrivateIdentifier
Add test for private identifier fields initialized to class exprs
Fix shebang errors
Fix private errors on index signatures
Add codefix for missing private property
Update error messages for unsupported private features
Fix inheritance-related errors
Fixes inheritance-related errors with private identifiers by resolving
properties from base classes. Private identifiers do not show up as
properties on a union type, so those do not type-check.
Add test for interface extending class with private access
Remove debugging log
Remove name assignment from private named functions
Rename to getPrivateIdentifierPropertyOfType
Fix index signature test comment
Fix test target syntax error
Change error messages
patch private identifiers outside class bodies
Add test for private identifier with ooo super
Add test for a class with a private identifier
with a non-preambly (for example, not a comment)
statement before 'super':
should error, saying 'super' must come first
Fix nits
incorporate PR feedback
Incorporate checker feedback
- reorganize if statements in checkFunctionOrConstructorSymbol
- remove overload for getPrivateIdentifierPropertyOfType
reorganize if statements in checkFunctionOrConstructorSymbol
test for private names with JSX
use getPropertyOftype in getPropertyForPrivateIdentifier
getPrivateIdentifierPropertyOfType error on synthetic
make getPrivateIdentifierPropertyOfType error
if given a node that is not from the parse tree
Simplify checkPrivateIdentifierPropertyAccess
use getPropertiesOfType instead of
rehashing that logic
test for private identifiers w decl merging
fix test target for privateNameDeclarationMerging
update baselines
Fix private identifier ++/-- numeric coercion
Remove 'downleveled' from super error
Fix bad comments in helper call emit
Error on private identifiers in JSX tag names
Add more private identifier tests
Add es2015 target for private name destructured binding test
Add privateNameConstructorSignature test
Add test for navigation bar w private identifier
Remove spurious line from test
// in js file
class A {
exports.#foo = 3; // should error
}
The above line failed to produce an error
when run using the test harness.
When using tsc or the language server,
we got the expected error message.
Removing the troublesome line, as it
seems to say more about the test runner
than about the code it is testing.
Fix inefficient constructor generation
dts: don't emit type for private-identified field
Do not emit types for private-identified fields
when generating declaration files.
// example.ts
export class A {
#foo: number;
}
// example.d.ts
export declare class A {
#foo;
}
**This is not ideal!**
The following would be better:
// example.d.ts
export declare unique class A {
#foo;
}
See discussion:
https://github.com/microsoft/TypeScript/pull/33038#issuecomment-530321165
notice when private-identified field unused
Notice when private-identified fields are unused,
and implement the same behavior as for unused
private-modified fields.
This is used in the language server to make things
grayed out.
This case generates an error when --noUnusedLocals
flag is passed to tsc:
- "<name> is declared but never used"
accept baselines
Revert "dts: don't emit type for private-identified field"
This reverts commit e50305df5fb88121486291abad14478f5339a455.
Instead of just excluding the type from private identifier
emit, only emit a single private identifier
per class.
This accomplishes nominality while
hiding implementation detail that
is irrelevant to .d.ts consumers
only emit a single private identifier in dts
In dts emit, emit at most one private identifier,
and rename it to `#private`.
refactor getPrivateIdentifierPropertyOfType
- safer check for wehther is parse tree node
- return undefined when not found (instead of
a Debug.fail)
Incorporate PR feedback
Don't rely on parent pointers in transform
Passes context about whether the postfix unary expression value is
discarded down the tree into the visitPostfixUnaryExpression function.
Remove orphaned test baseline files
remove unreachable if
Check `any`-typed private identified fields
Update private identifier incompatible modifier checks
- disallow 'abstract' with private identifiers
- s/private-named-property/private identifier
Add additional call expression test cases
Fix disallow 'abstract' with private identifier
Static private identifiers not inherited
Including this in the PR for private
instance fields even though static
private identifiers are banned.
Reason: this change
improves quality of error messages,
see test case.
Thanks Ron!
Simplifiy private identifier 'any' type handling
Error on private identifier declarations for ES5/ES3
Bind `this` for private identifier property tagged template literals
Fix target for jsdocPrivateName1 test
Update getPrivateIdentifierPropertyOfType API
Make it easier to use by accepting a string
and location, rather than a PrivateIdentifier.
Thanks Ron!
remove orphaned tests
rename test
remove duplicate tests
Remove unrelated error from test
update diagnostic message 'private identifier'
The nodes for hash private fields are now
called 'private identifier'. Update one last
diagnostic message to use the new terminology.
refine solution for static private identifier fields
- use `continue` instead of `filter` for perf
- better naming
- make it clear the current solution will
need to be altered when we lift the ban on
static private identifier fields, including
a test case that should change in the future
Fix display of private identifiers in lang server
Fix bug where private identifiers in completion
tooltips in the playground were showing up
as the symbol table entries (with underscores and such).
https://github.com/microsoft/TypeScript/pull/30829#issuecomment-534157560
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* fix privateIdentifier w !useDefineForClassFields
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Disallow PrivateIdentifier in Optional Chains
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* restrict privateIdentifier completions correctly
Don't autocomplete privateIdentifiers in
places where they are not allowed.
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* make PrivateIdentifier not a PropertyNameLiteral
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Added test.
* Accepted baselines.
* Update symbol serializer to understand private fields in JS `.d.ts` emit.
* Accepted baselines.
* fix for private field no initializer esnext
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* fix private fields .d.ts emit for JS w expando
fix bug where the following in a JS file
would lead to a `#private` in the .d.ts:
```js
class C {
constructor () {
this.a = 3
}
}
```
Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2019-12-27 22:07:35 +01:00
2021-02-26 08:01:41 +01:00
// SyntaxKind.UnparsedSource
// SyntaxKind.UnparsedPrepend
function emitUnparsedSourceOrPrepend ( unparsed : UnparsedSource | UnparsedPrepend ) {
for ( const text of unparsed . texts ) {
writeLine ( ) ;
emit ( text ) ;
}
}
2018-05-04 01:04:52 +02:00
2021-02-26 08:01:41 +01:00
// SyntaxKind.UnparsedPrologue
// SyntaxKind.UnparsedText
// SyntaxKind.UnparsedInternal
// SyntaxKind.UnparsedSyntheticReference
function writeUnparsedNode ( unparsed : UnparsedNode ) {
writer . rawWrite ( unparsed . parent . text . substring ( unparsed . pos , unparsed . end ) ) ;
}
2019-01-17 21:11:51 +01:00
2019-02-15 18:46:37 +01:00
// SyntaxKind.UnparsedText
2019-02-22 23:33:47 +01:00
// SyntaxKind.UnparsedInternal
2019-02-15 18:46:37 +01:00
function emitUnparsedTextLike ( unparsed : UnparsedTextLike ) {
const pos = getTextPosWithWriteLine ( ) ;
writeUnparsedNode ( unparsed ) ;
if ( bundleFileInfo ) {
2019-02-15 23:25:24 +01:00
updateOrPushBundleFileTextLike (
2019-02-15 18:46:37 +01:00
pos ,
2019-02-15 23:25:24 +01:00
writer . getTextPos ( ) ,
unparsed . kind === SyntaxKind . UnparsedText ?
BundleFileSectionKind . Text :
2019-02-22 23:33:47 +01:00
BundleFileSectionKind . Internal
2019-02-15 23:25:24 +01:00
) ;
2019-02-15 18:46:37 +01:00
}
}
2019-02-20 19:54:31 +01:00
// SyntaxKind.UnparsedSyntheticReference
function emitUnparsedSyntheticReference ( unparsed : UnparsedSyntheticReference ) {
2019-02-02 05:10:31 +01:00
const pos = getTextPosWithWriteLine ( ) ;
2019-02-15 18:46:37 +01:00
writeUnparsedNode ( unparsed ) ;
2019-02-02 05:10:31 +01:00
if ( bundleFileInfo ) {
const section = clone ( unparsed . section ) ;
section . pos = pos ;
section . end = writer . getTextPos ( ) ;
bundleFileInfo . sections . push ( section ) ;
}
}
2016-06-07 19:32:03 +02:00
//
// Identifiers
//
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitIdentifier ( node : Identifier ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
const writeText = node . symbol ? writeSymbol : write ;
writeText ( getTextOfNode ( node , /*includeTrivia*/ false ) , node . symbol ) ;
emitList ( node , node . typeArguments , ListFormat . TypeParameters ) ; // Call emitList directly since it could be an array of TypeParameterDeclarations _or_ type arguments
2016-06-07 19:32:03 +02:00
}
2014-07-17 00:39:14 +02:00
2016-06-07 19:32:03 +02:00
//
// Names
//
2015-03-23 19:06:44 +01:00
Private named instance fields (#30829)
* Fix display of private names in language server
Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Parse private names
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* update parser error recovery tests to use ¬ not #
The intent of the tests seemed to be to
regiment the behavior of the parser
when a weird symbol is encountered.
The `#` is now taken by private identifiers,
so `¬` seems like a good new choice for
keeping the diff small, since it also fits in
16 bits (wide emojis would be treated
as multiple characters, since the scanner
uses ++).
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Private Name Support in the Checker (#5)
- [x] treat private names as unique:
- case 1: cannot say that a variable is of a class type unless the variable points to an instance of the class
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesUnique.ts)
- case 2: private names in class hierarchies do not conflict
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoConflictWhenInheriting.ts)
- [x] `#constructor` is reserved
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts)
- check in `bindWorker`, where every node is visited
- [x] Accessibility modifiers can't be used with private names
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoAccessibilityModifiers.ts)
- implemented in `checkAccessibilityModifiers`, using `ModifierFlags.AccessibilityModifier`
- [x] `delete #foo` not allowed
- [x] Private name accesses not allowed outside of the defining class
- see test: https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameNotAccessibleOutsideDefiningClass.ts
- see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts)
- implemented in `checkDeleteExpression`
- [x] Do [the right thing](https://gist.github.com/mheiber/b6fc7adb426c2e1cdaceb5d7786fc630) for nested classes
mv private name tests together
more checker tests for private names
update naming and cleanup for check private names
for private name support in the checker:
- make names more consistent
- remove unnecessary checks
- add utility function to public API
- other small cleanup
Move getPropertyNameForUniqueESSymbol to utility
for consistency with other calculation of
special property names (starting with __),
move the calculation of property names for
unique es symbols to `utilities.ts`.
private name tests strict+es6
Update private name tests to use 'strict'
type checking and to target es6 instead of
default. Makes the js output easier to read
and tests more surface area with other
checker features.
error message for private names in obj literals
Disallow decorating private-named properties
because the spec is still in flux.
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Add private instance field transformation, pr feedback
Implements private instance fields on top of the class properties refactor.
This commit also includes incorporation of PR feedback on the
checker, parser, and transformer in order to make the rebase
manageable.
Co-Authored-By: Max Heiber <max.heiber@gmail.com>
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
Signed-off-by: Joey Watts <jwatts43@bloomberg.net>
Signed-off-by: Max Heiber <max.heiber@gmail.com>
Incorporate PR feedback
Fix checker crash with new block scoped bindings
Add classExpressionInLoop test
Update baselines for private name errors
Apply suggestions from code review
Fix privateNameFieldCallExpression test
Remove unnecessary comment
Fix PropertyAccessEntityNameExpression type
Remove PrivateName from PropertyNameLiteral
Add createPrivateName
Remove PrivateName type from textSourceNode
Add Debug asserts for invalid syntax kinds
Don't output private name syntax when undeclared
Make PrivateName extend Node
Update baselines for public API
Fix completions in language server
Fix fourslash test crash
intern private name descriptions
undo expensive node.name.parent assignment
Back the way things were on `master`: only
assign node.name.parent when we need to
Add tests for private names and JSDoc
Patch hoverOverPrivateName fourslash test
Fix goToDefinition for private-named fields
remove Debug.fail for private name outside class
Remove Debug.fail in binder.ts::`getDeclarationName`.
It turns out this code path *does* get hit (intentionally).
For best error messages, return `undefined` and rely
on the parser generating a good error message
"Private names are not allowed outside class bodies"
Add rbuckton test cases for private names
These test cases specifically exercise where
we needed to use name-mangling. They are
cases where private names have the same
description.
- private names no conflict when inheriting
- private names distinct even when
the two classes have the same name
check dup instance+static private identifiers
class A {
#foo;
static #foo;
}
not allowed because static and private names
share the same lexical scope
https://tc39.es/proposal-class-fields/#prod-ClassBody
refactor getPropertyForPrivateName, rel spans
refactor getPropertyForPrivateName so
it is easier to read (use findAncestor instead
of loop).
Fix bugs in getPropertyForPrivateName:
- make it work with deeply-nested classes with
and without shadowing
- make it catch shadowing when the conflict is
between static and instance
private name descriptions (these can actually
clash)
And add related spans to diagnostics
for getPropertyForPrivateName
catch conflicts between static and instance
private identifiers:
- cannot have an instance and static private identifier
with the same spelling, as there is only one namespace
for private names
rename 'PrivateName' to 'PrivateIdentifier'
to match the change of wording in the spec
prposal:
https://tc39.es/proposal-class-fields/#sec-syntax
The rename in the spec was to avoid confusion
between the AST Node PrivateIdentifier
and the internal spec type PrivateName.
So one uses the [[Description]] of a
PrivateIdentifier to look up the PrivateName
for a given scope.
This corresponds closely to our implementation
in the binder and checker:
- we mangle PrivateIdentifier.escapedText to
get a `key` which we use to get the symbol
for a property
f
getLiteralTypeFromProperty-check privateIdentifier
rename and simplify privateNameAndAny test case
make it clearer that all this test is showing is
that we allow accessing arbitrary private identifiers
on `any`.
Note: we could have something more sound here by
checking that there is a private-named field declaration
in a class scope above the property access.
Discussion:
https://github.com/microsoft/TypeScript/pull/30829/files#r302760015
Fix typo in checker
s/identifer/identifier
remove accidental change
patch fourslash test broken by isPrivateIdentifier
just needed to add a check to see if the symbol
.name is defined
extract reportUnmatchedProperty
per @nsandersn feedback
propertiesRelatedTo was getting to long
pull out the unmatchedProperty reporting into
a seprate function
fix typo in private names test
Fix type soundness with private names
Remove PrivateIdentifier from emit with Expr hint
Fixup helpers and set function name for privates
remove accidentally-committed baselines
These baselines somehow ended up in this pr,
though they have nothing to do with the changes
Revert "getLiteralTypeFromProperty-check privateIdentifier"
This reverts commit bd1155c300bc3517a0543580f4790268f86e473f.
reason: the check for isIdentifier in
getLiteralTypeFromProperty is superfluous because
we do this check in getLiteralTypeFromPropertyName
Update comment in private name uniqueness test 3
I think the comments were not accurate and that we
export the error on `this.#x = child.#x` because:
- private names are lexically scoped: the code in question is not in a
lexical scope under the definition of Child's #x.
- private names are private to their containing class: never inherited
This expected behavior matches that of Chrome Canary and
my understanding of the spec
test private names use before def, circular ref
test private names use before def, circular ref
update diagnosticMessages s/delete/'delete'
per @DanielRosenwasser and @sandersn guidance,
use this style in diagnostic messages:
"operand of a 'delete' operator" (single quotes)
rather than old style:
"operand of a delete operator" (single quotes)
This is for consistency, as we use the new
style in the privateIdentifiers error messages
and it is consistent with our messages about
other operators
incorporate private names early exit feedback
and code style change to use a ternary
instead of if so we can 'const'
require private-named fields to be declared in JS
All fields must be declared in TS files.
In JS files, we typically do not have this requirement.
So special-case private fields, which must always
be declared (even in JS files, per spec)
update debug failure for es2015 private identifier
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
fix checker handling of private name in subclasse
update checker and tests to account for the
following ts features:
- private names do not participate in
the prototype chain, but *are* assigned
in the parent class' constructor. So
parent can access its *own* private fields
on instances of the subclass
Add more tests for private-named fields in JS
add test to hit symbolToExpression w private names
symbolToExpression knows about private names
add a test to exercise this code path
ban private-named static methods (not supported yet)
ban private-named methods (not supported yet)
ban private-named accessors (not supported yet)
fix privateIdentifier fourslash test
change assertion throw to return
Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com>
Update comment in checker.ts re reserved members
Remove case for privateIdentifier in EntityNameExpr
Remove case for privateIdentifier in
EntityNameExpr. That code path is never hit,
and privateIdnetifiers cannot be entity names.
remove unnecessary parentheses
Ban private identifier in enum
As the new test, 'privateNameEnumNoEmit',
shows, the checker now correctly makes
a diagnostic for private identifiers in enums.
However, when noEmit is false we
hit this assertion in the transformer.
This assertion will have to be removed
so that we have a diagnostic here instead
of an assertion error.
When the assertion is removed,
the 'privateNameEnum' baseline
will have to be updated
Fix destructuring assignment, use createCallBinding, remove unneeded helper
Add class private field helpers to external helpers
Remove private identifier enum assertion, use missing identifiers
Fix hash map inefficiency by only using get
Update baselines with empty identifier change
Add privateNameEnum test baselines
Fix private identifier destructuring (array assignment defaults, unique names)
Use createPrivateIdentifierAssignment in destructuring transform
Fix lint error
Separate destructuring target visitor from regular visitor
Fix destructuring assignment with this bindings
Fix destructuring assignment with this bindings
Fix syntax error with destructuring assignment output
Disallow private identifiers in property signatures
remove duplicate test baselines
Add tests for undeclarated private identifiers
remove unnecessary cast
Nicer error message for mis-placed hashbang
Workaround v8 bug with destructured assignments
Optimize private identifier stack lookup
Avoid the cost of performing an array lookup to look at the top of the
private identifier environment stack.
Change function name to be more specific
Changes "getOperatorForCompoundAssignment" to
"getNonAssignmentOperatorForCompoundAssignment" now that this
function is accessible to the entire compiler.
Improve test case for private name assignment
Adds a compound assignment test case for a class with private names
being declared on the left-hand-side of the assignment expression.
Remove extra non-private-field test
Remove isPrivateIdentifierAssignmentExpression helper
Don't transform private names in ESNext target
Preserve private fields initialized to functions
Move function expressions to outer scope for efficiency
Add WeakMap collision check
Modify potential WeakMap collision condition
Fix this property assignment binding with private names
Add correct error message for WeakMap collision
Add error for statements before super with private identifiers
Refactor getPropertyForPrivateIdentifier
Add test for private identifier fields initialized to class exprs
Fix shebang errors
Fix private errors on index signatures
Add codefix for missing private property
Update error messages for unsupported private features
Fix inheritance-related errors
Fixes inheritance-related errors with private identifiers by resolving
properties from base classes. Private identifiers do not show up as
properties on a union type, so those do not type-check.
Add test for interface extending class with private access
Remove debugging log
Remove name assignment from private named functions
Rename to getPrivateIdentifierPropertyOfType
Fix index signature test comment
Fix test target syntax error
Change error messages
patch private identifiers outside class bodies
Add test for private identifier with ooo super
Add test for a class with a private identifier
with a non-preambly (for example, not a comment)
statement before 'super':
should error, saying 'super' must come first
Fix nits
incorporate PR feedback
Incorporate checker feedback
- reorganize if statements in checkFunctionOrConstructorSymbol
- remove overload for getPrivateIdentifierPropertyOfType
reorganize if statements in checkFunctionOrConstructorSymbol
test for private names with JSX
use getPropertyOftype in getPropertyForPrivateIdentifier
getPrivateIdentifierPropertyOfType error on synthetic
make getPrivateIdentifierPropertyOfType error
if given a node that is not from the parse tree
Simplify checkPrivateIdentifierPropertyAccess
use getPropertiesOfType instead of
rehashing that logic
test for private identifiers w decl merging
fix test target for privateNameDeclarationMerging
update baselines
Fix private identifier ++/-- numeric coercion
Remove 'downleveled' from super error
Fix bad comments in helper call emit
Error on private identifiers in JSX tag names
Add more private identifier tests
Add es2015 target for private name destructured binding test
Add privateNameConstructorSignature test
Add test for navigation bar w private identifier
Remove spurious line from test
// in js file
class A {
exports.#foo = 3; // should error
}
The above line failed to produce an error
when run using the test harness.
When using tsc or the language server,
we got the expected error message.
Removing the troublesome line, as it
seems to say more about the test runner
than about the code it is testing.
Fix inefficient constructor generation
dts: don't emit type for private-identified field
Do not emit types for private-identified fields
when generating declaration files.
// example.ts
export class A {
#foo: number;
}
// example.d.ts
export declare class A {
#foo;
}
**This is not ideal!**
The following would be better:
// example.d.ts
export declare unique class A {
#foo;
}
See discussion:
https://github.com/microsoft/TypeScript/pull/33038#issuecomment-530321165
notice when private-identified field unused
Notice when private-identified fields are unused,
and implement the same behavior as for unused
private-modified fields.
This is used in the language server to make things
grayed out.
This case generates an error when --noUnusedLocals
flag is passed to tsc:
- "<name> is declared but never used"
accept baselines
Revert "dts: don't emit type for private-identified field"
This reverts commit e50305df5fb88121486291abad14478f5339a455.
Instead of just excluding the type from private identifier
emit, only emit a single private identifier
per class.
This accomplishes nominality while
hiding implementation detail that
is irrelevant to .d.ts consumers
only emit a single private identifier in dts
In dts emit, emit at most one private identifier,
and rename it to `#private`.
refactor getPrivateIdentifierPropertyOfType
- safer check for wehther is parse tree node
- return undefined when not found (instead of
a Debug.fail)
Incorporate PR feedback
Don't rely on parent pointers in transform
Passes context about whether the postfix unary expression value is
discarded down the tree into the visitPostfixUnaryExpression function.
Remove orphaned test baseline files
remove unreachable if
Check `any`-typed private identified fields
Update private identifier incompatible modifier checks
- disallow 'abstract' with private identifiers
- s/private-named-property/private identifier
Add additional call expression test cases
Fix disallow 'abstract' with private identifier
Static private identifiers not inherited
Including this in the PR for private
instance fields even though static
private identifiers are banned.
Reason: this change
improves quality of error messages,
see test case.
Thanks Ron!
Simplifiy private identifier 'any' type handling
Error on private identifier declarations for ES5/ES3
Bind `this` for private identifier property tagged template literals
Fix target for jsdocPrivateName1 test
Update getPrivateIdentifierPropertyOfType API
Make it easier to use by accepting a string
and location, rather than a PrivateIdentifier.
Thanks Ron!
remove orphaned tests
rename test
remove duplicate tests
Remove unrelated error from test
update diagnostic message 'private identifier'
The nodes for hash private fields are now
called 'private identifier'. Update one last
diagnostic message to use the new terminology.
refine solution for static private identifier fields
- use `continue` instead of `filter` for perf
- better naming
- make it clear the current solution will
need to be altered when we lift the ban on
static private identifier fields, including
a test case that should change in the future
Fix display of private identifiers in lang server
Fix bug where private identifiers in completion
tooltips in the playground were showing up
as the symbol table entries (with underscores and such).
https://github.com/microsoft/TypeScript/pull/30829#issuecomment-534157560
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* fix privateIdentifier w !useDefineForClassFields
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Disallow PrivateIdentifier in Optional Chains
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* restrict privateIdentifier completions correctly
Don't autocomplete privateIdentifiers in
places where they are not allowed.
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* make PrivateIdentifier not a PropertyNameLiteral
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* Added test.
* Accepted baselines.
* Update symbol serializer to understand private fields in JS `.d.ts` emit.
* Accepted baselines.
* fix for private field no initializer esnext
Signed-off-by: Max Heiber <max.heiber@gmail.com>
* fix private fields .d.ts emit for JS w expando
fix bug where the following in a JS file
would lead to a `#private` in the .d.ts:
```js
class C {
constructor () {
this.a = 3
}
}
```
Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2019-12-27 22:07:35 +01:00
function emitPrivateIdentifier ( node : PrivateIdentifier ) {
const writeText = node . symbol ? writeSymbol : write ;
writeText ( getTextOfNode ( node , /*includeTrivia*/ false ) , node . symbol ) ;
}
2016-06-07 19:32:03 +02:00
function emitQualifiedName ( node : QualifiedName ) {
emitEntityName ( node . left ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "." ) ;
2016-06-07 19:32:03 +02:00
emit ( node . right ) ;
}
function emitEntityName ( node : EntityName ) {
if ( node . kind === SyntaxKind . Identifier ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node ) ;
2016-06-07 19:32:03 +02:00
}
else {
emit ( node ) ;
2014-07-17 00:39:14 +02:00
}
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitComputedPropertyName ( node : ComputedPropertyName ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "[" ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionOfComputedPropertyName ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "]" ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-26 01:24:41 +02:00
2016-06-07 19:32:03 +02:00
//
// Signature elements
//
2015-06-26 01:24:41 +02:00
2016-06-07 19:32:03 +02:00
function emitTypeParameter ( node : TypeParameterDeclaration ) {
emit ( node . name ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
if ( node . constraint ) {
writeSpace ( ) ;
writeKeyword ( "extends" ) ;
writeSpace ( ) ;
emit ( node . constraint ) ;
}
if ( node . default ) {
writeSpace ( ) ;
writeOperator ( "=" ) ;
writeSpace ( ) ;
emit ( node . default ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitParameter ( node : ParameterDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
2018-05-04 01:04:52 +02:00
emit ( node . dotDotDotToken ) ;
emitNodeWithWriter ( node . name , writeParameter ) ;
emit ( node . questionToken ) ;
2017-09-26 21:42:08 +02:00
if ( node . parent && node . parent . kind === SyntaxKind . JSDocFunctionType && ! node . name ) {
2018-05-04 01:04:52 +02:00
emit ( node . type ) ;
2017-09-26 21:42:08 +02:00
}
else {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2017-09-26 21:42:08 +02:00
}
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
// The comment position has to fallback to any present node within the parameterdeclaration because as it turns out, the parser can make parameter declarations with _just_ an initializer.
2021-04-19 18:34:46 +02:00
emitInitializer ( node . initializer , node . type ? node.type.end : node.questionToken ? node.questionToken.end : node.name ? node.name.end : node.modifiers ? node.modifiers.end : node.decorators ? node.decorators.end : node.pos , node , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitDecorator ( decorator : Decorator ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "@" ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( decorator . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
//
// Type members
//
function emitPropertySignature ( node : PropertySignature ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitNodeWithWriter ( node . name , writeProperty ) ;
2018-05-04 01:04:52 +02:00
emit ( node . questionToken ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitPropertyDeclaration ( node : PropertyDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
emit ( node . name ) ;
2018-05-04 01:04:52 +02:00
emit ( node . questionToken ) ;
emit ( node . exclamationToken ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
emitInitializer ( node . initializer , node . type ? node.type.end : node.questionToken ? node.questionToken.end : node.name.end , node ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-23 19:06:44 +01:00
2016-06-07 19:32:03 +02:00
function emitMethodSignature ( node : MethodSignature ) {
2018-05-10 20:16:27 +02:00
pushNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
emit ( node . name ) ;
2018-05-04 01:04:52 +02:00
emit ( node . questionToken ) ;
2016-06-07 19:32:03 +02:00
emitTypeParameters ( node , node . typeParameters ) ;
emitParameters ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2018-05-10 20:16:27 +02:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-17 00:39:14 +02:00
2016-06-07 19:32:03 +02:00
function emitMethodDeclaration ( node : MethodDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
2018-05-04 01:04:52 +02:00
emit ( node . asteriskToken ) ;
2016-06-07 19:32:03 +02:00
emit ( node . name ) ;
2018-05-04 01:04:52 +02:00
emit ( node . questionToken ) ;
2016-06-07 19:32:03 +02:00
emitSignatureAndBody ( node , emitSignatureHead ) ;
}
2014-08-22 23:40:47 +02:00
2021-06-25 18:24:05 +02:00
function emitClassStaticBlockDeclaration ( node : ClassStaticBlockDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
writeKeyword ( "static" ) ;
emitBlockFunctionBody ( node . body ) ;
}
2016-06-07 19:32:03 +02:00
function emitConstructor ( node : ConstructorDeclaration ) {
emitModifiers ( node , node . modifiers ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( "constructor" ) ;
2016-06-07 19:32:03 +02:00
emitSignatureAndBody ( node , emitSignatureHead ) ;
}
2014-07-13 01:04:16 +02:00
2016-06-07 19:32:03 +02:00
function emitAccessorDeclaration ( node : AccessorDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( node . kind === SyntaxKind . GetAccessor ? "get" : "set" ) ;
writeSpace ( ) ;
2016-06-07 19:32:03 +02:00
emit ( node . name ) ;
emitSignatureAndBody ( node , emitSignatureHead ) ;
}
2014-08-15 00:41:57 +02:00
2016-06-07 19:32:03 +02:00
function emitCallSignature ( node : CallSignatureDeclaration ) {
2018-05-10 20:16:27 +02:00
pushNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
emitTypeParameters ( node , node . typeParameters ) ;
emitParameters ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2018-05-10 20:16:27 +02:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-07 00:28:06 +01:00
2016-06-07 19:32:03 +02:00
function emitConstructSignature ( node : ConstructSignatureDeclaration ) {
2018-05-10 20:16:27 +02:00
pushNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( "new" ) ;
writeSpace ( ) ;
2016-06-07 19:32:03 +02:00
emitTypeParameters ( node , node . typeParameters ) ;
emitParameters ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2018-05-10 20:16:27 +02:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-07 00:28:06 +01:00
2016-06-07 19:32:03 +02:00
function emitIndexSignature ( node : IndexSignatureDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
emitParametersForIndexSignature ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-24 21:33:35 +01:00
2020-09-10 05:23:22 +02:00
function emitTemplateTypeSpan ( node : TemplateLiteralTypeSpan ) {
emit ( node . type ) ;
emit ( node . literal ) ;
}
2016-10-10 22:06:58 +02:00
function emitSemicolonClassElement() {
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2016-06-07 19:32:03 +02:00
//
// Types
//
2014-07-13 01:04:16 +02:00
2016-06-07 19:32:03 +02:00
function emitTypePredicate ( node : TypePredicateNode ) {
2019-08-03 02:57:26 +02:00
if ( node . assertsModifier ) {
emit ( node . assertsModifier ) ;
writeSpace ( ) ;
}
2016-06-07 19:32:03 +02:00
emit ( node . parameterName ) ;
2019-08-03 02:57:26 +02:00
if ( node . type ) {
writeSpace ( ) ;
writeKeyword ( "is" ) ;
writeSpace ( ) ;
emit ( node . type ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-01-07 00:28:06 +01:00
2016-06-07 19:32:03 +02:00
function emitTypeReference ( node : TypeReferenceNode ) {
emit ( node . typeName ) ;
emitTypeArguments ( node , node . typeArguments ) ;
}
2014-11-21 05:24:08 +01:00
2016-06-07 19:32:03 +02:00
function emitFunctionType ( node : FunctionTypeNode ) {
2018-05-10 20:16:27 +02:00
pushNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
emitTypeParameters ( node , node . typeParameters ) ;
emitParametersForArrow ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
writePunctuation ( "=>" ) ;
writeSpace ( ) ;
2018-05-04 01:04:52 +02:00
emit ( node . type ) ;
2018-05-10 20:16:27 +02:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2017-09-26 21:42:08 +02:00
function emitJSDocFunctionType ( node : JSDocFunctionType ) {
2018-08-22 21:42:36 +02:00
writeKeyword ( "function" ) ;
2017-09-26 21:42:08 +02:00
emitParameters ( node , node . parameters ) ;
2018-08-22 21:42:36 +02:00
writePunctuation ( ":" ) ;
2018-05-04 01:04:52 +02:00
emit ( node . type ) ;
2017-09-26 21:42:08 +02:00
}
2017-09-25 17:56:51 +02:00
function emitJSDocNullableType ( node : JSDocNullableType ) {
2018-08-22 21:42:36 +02:00
writePunctuation ( "?" ) ;
2017-09-25 17:56:51 +02:00
emit ( node . type ) ;
}
function emitJSDocNonNullableType ( node : JSDocNonNullableType ) {
2018-08-22 21:42:36 +02:00
writePunctuation ( "!" ) ;
2017-09-25 17:56:51 +02:00
emit ( node . type ) ;
}
function emitJSDocOptionalType ( node : JSDocOptionalType ) {
emit ( node . type ) ;
2018-08-22 21:42:36 +02:00
writePunctuation ( "=" ) ;
2017-09-25 17:56:51 +02:00
}
2016-06-07 19:32:03 +02:00
function emitConstructorType ( node : ConstructorTypeNode ) {
2018-05-10 20:16:27 +02:00
pushNameGenerationScope ( node ) ;
2021-01-08 02:11:14 +01:00
emitModifiers ( node , node . modifiers ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( "new" ) ;
writeSpace ( ) ;
2016-06-07 19:32:03 +02:00
emitTypeParameters ( node , node . typeParameters ) ;
2017-06-08 00:13:24 +02:00
emitParameters ( node , node . parameters ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
writePunctuation ( "=>" ) ;
writeSpace ( ) ;
2018-05-04 01:04:52 +02:00
emit ( node . type ) ;
2018-05-10 20:16:27 +02:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2014-08-22 23:17:52 +02:00
2016-06-07 19:32:03 +02:00
function emitTypeQuery ( node : TypeQueryNode ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( "typeof" ) ;
writeSpace ( ) ;
2016-06-07 19:32:03 +02:00
emit ( node . exprName ) ;
}
2015-06-18 23:01:49 +02:00
2016-06-07 19:32:03 +02:00
function emitTypeLiteral ( node : TypeLiteralNode ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "{" ) ;
2017-09-07 23:30:19 +02:00
const flags = getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers ;
emitList ( node , node . members , flags | ListFormat . NoSpaceIfEmpty ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "}" ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2016-06-07 19:32:03 +02:00
function emitArrayType ( node : ArrayTypeNode ) {
2021-04-19 18:34:46 +02:00
emit ( node . elementType , parenthesizer . parenthesizeElementTypeOfArrayType ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "[" ) ;
writePunctuation ( "]" ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2018-06-15 20:43:16 +02:00
function emitRestOrJSDocVariadicType ( node : RestTypeNode | JSDocVariadicType ) {
2018-08-22 21:42:36 +02:00
writePunctuation ( "..." ) ;
2017-09-25 17:56:51 +02:00
emit ( node . type ) ;
}
2016-06-07 19:32:03 +02:00
function emitTupleType ( node : TupleTypeNode ) {
2020-05-20 00:54:02 +02:00
emitTokenWithComment ( SyntaxKind . OpenBracketToken , node . pos , writePunctuation , node ) ;
const flags = getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat.SingleLineTupleTypeElements : ListFormat.MultiLineTupleTypeElements ;
emitList ( node , node . elements , flags | ListFormat . NoSpaceIfEmpty ) ;
emitTokenWithComment ( SyntaxKind . CloseBracketToken , node . elements . end , writePunctuation , node ) ;
}
function emitNamedTupleMember ( node : NamedTupleMember ) {
emit ( node . dotDotDotToken ) ;
emit ( node . name ) ;
emit ( node . questionToken ) ;
emitTokenWithComment ( SyntaxKind . ColonToken , node . name . end , writePunctuation , node ) ;
writeSpace ( ) ;
emit ( node . type ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2018-06-09 21:19:11 +02:00
function emitOptionalType ( node : OptionalTypeNode ) {
2021-04-19 18:34:46 +02:00
emit ( node . type , parenthesizer . parenthesizeElementTypeOfArrayType ) ;
2018-08-22 21:42:36 +02:00
writePunctuation ( "?" ) ;
2018-06-09 21:19:11 +02:00
}
2016-06-07 19:32:03 +02:00
function emitUnionType ( node : UnionTypeNode ) {
2021-04-19 18:34:46 +02:00
emitList ( node , node . types , ListFormat . UnionTypeConstituents , parenthesizer . parenthesizeMemberOfElementType ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2016-06-07 19:32:03 +02:00
function emitIntersectionType ( node : IntersectionTypeNode ) {
2021-04-19 18:34:46 +02:00
emitList ( node , node . types , ListFormat . IntersectionTypeConstituents , parenthesizer . parenthesizeMemberOfElementType ) ;
2016-06-07 19:32:03 +02:00
}
2016-01-29 08:29:08 +01:00
2017-12-05 23:18:11 +01:00
function emitConditionalType ( node : ConditionalTypeNode ) {
2021-04-19 18:34:46 +02:00
emit ( node . checkType , parenthesizer . parenthesizeMemberOfConditionalType ) ;
2018-02-03 20:32:24 +01:00
writeSpace ( ) ;
writeKeyword ( "extends" ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emit ( node . extendsType , parenthesizer . parenthesizeMemberOfConditionalType ) ;
2018-02-03 20:32:24 +01:00
writeSpace ( ) ;
writePunctuation ( "?" ) ;
writeSpace ( ) ;
2017-12-05 23:18:11 +01:00
emit ( node . trueType ) ;
2018-02-03 20:32:24 +01:00
writeSpace ( ) ;
writePunctuation ( ":" ) ;
writeSpace ( ) ;
2017-12-05 23:18:11 +01:00
emit ( node . falseType ) ;
}
2018-01-25 21:25:00 +01:00
function emitInferType ( node : InferTypeNode ) {
2018-02-03 20:32:24 +01:00
writeKeyword ( "infer" ) ;
writeSpace ( ) ;
2018-01-25 21:25:00 +01:00
emit ( node . typeParameter ) ;
}
2016-06-07 19:32:03 +02:00
function emitParenthesizedType ( node : ParenthesizedTypeNode ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "(" ) ;
2016-06-07 19:32:03 +02:00
emit ( node . type ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( ")" ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-03 02:02:26 +02:00
2016-10-10 22:06:58 +02:00
function emitThisType() {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeKeyword ( "this" ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-03 02:02:26 +02:00
2016-10-25 00:24:26 +02:00
function emitTypeOperator ( node : TypeOperatorNode ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeTokenText ( node . operator , writeKeyword ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emit ( node . type , parenthesizer . parenthesizeMemberOfElementType ) ;
2016-10-25 00:24:26 +02:00
}
2016-11-11 00:20:29 +01:00
function emitIndexedAccessType ( node : IndexedAccessTypeNode ) {
2021-04-19 18:34:46 +02:00
emit ( node . objectType , parenthesizer . parenthesizeMemberOfElementType ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "[" ) ;
2016-10-26 22:39:12 +02:00
emit ( node . indexType ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "]" ) ;
2016-10-25 23:32:20 +02:00
}
2016-11-11 00:20:29 +01:00
function emitMappedType ( node : MappedTypeNode ) {
2017-05-09 22:14:39 +02:00
const emitFlags = getEmitFlags ( node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "{" ) ;
2017-05-09 22:14:39 +02:00
if ( emitFlags & EmitFlags . SingleLine ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2017-05-09 22:14:39 +02:00
}
else {
writeLine ( ) ;
increaseIndent ( ) ;
}
2017-09-07 23:30:19 +02:00
if ( node . readonlyToken ) {
emit ( node . readonlyToken ) ;
2018-02-13 01:20:49 +01:00
if ( node . readonlyToken . kind !== SyntaxKind . ReadonlyKeyword ) {
writeKeyword ( "readonly" ) ;
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2017-09-07 23:30:19 +02:00
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "[" ) ;
2018-05-04 01:04:52 +02:00
2021-04-19 18:34:46 +02:00
pipelineEmit ( EmitHint . MappedTypeParameter , node . typeParameter ) ;
2020-09-10 05:23:22 +02:00
if ( node . nameType ) {
writeSpace ( ) ;
writeKeyword ( "as" ) ;
writeSpace ( ) ;
emit ( node . nameType ) ;
}
2018-05-04 01:04:52 +02:00
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( "]" ) ;
2018-02-13 01:20:49 +01:00
if ( node . questionToken ) {
emit ( node . questionToken ) ;
if ( node . questionToken . kind !== SyntaxKind . QuestionToken ) {
writePunctuation ( "?" ) ;
}
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writePunctuation ( ":" ) ;
writeSpace ( ) ;
2018-05-04 01:04:52 +02:00
emit ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2017-05-09 22:14:39 +02:00
if ( emitFlags & EmitFlags . SingleLine ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2017-05-09 22:14:39 +02:00
}
else {
writeLine ( ) ;
decreaseIndent ( ) ;
}
2021-02-26 08:01:41 +01:00
writePunctuation ( "}" ) ;
}
function emitLiteralType ( node : LiteralTypeNode ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . literal ) ;
2021-02-26 08:01:41 +01:00
}
function emitTemplateType ( node : TemplateLiteralTypeNode ) {
emit ( node . head ) ;
emitList ( node , node . templateSpans , ListFormat . TemplateExpressionSpans ) ;
}
function emitImportTypeNode ( node : ImportTypeNode ) {
if ( node . isTypeOf ) {
writeKeyword ( "typeof" ) ;
writeSpace ( ) ;
}
writeKeyword ( "import" ) ;
writePunctuation ( "(" ) ;
emit ( node . argument ) ;
writePunctuation ( ")" ) ;
if ( node . qualifier ) {
writePunctuation ( "." ) ;
emit ( node . qualifier ) ;
}
emitTypeArguments ( node , node . typeArguments ) ;
}
//
// Binding patterns
//
function emitObjectBindingPattern ( node : ObjectBindingPattern ) {
writePunctuation ( "{" ) ;
emitList ( node , node . elements , ListFormat . ObjectBindingPatternElements ) ;
writePunctuation ( "}" ) ;
}
function emitArrayBindingPattern ( node : ArrayBindingPattern ) {
writePunctuation ( "[" ) ;
emitList ( node , node . elements , ListFormat . ArrayBindingPatternElements ) ;
writePunctuation ( "]" ) ;
}
function emitBindingElement ( node : BindingElement ) {
emit ( node . dotDotDotToken ) ;
if ( node . propertyName ) {
emit ( node . propertyName ) ;
writePunctuation ( ":" ) ;
writeSpace ( ) ;
}
emit ( node . name ) ;
2021-04-19 18:34:46 +02:00
emitInitializer ( node . initializer , node . name . end , node , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
//
// Expressions
//
function emitArrayLiteralExpression ( node : ArrayLiteralExpression ) {
const elements = node . elements ;
const preferNewLine = node . multiLine ? ListFormat.PreferNewLine : ListFormat.None ;
2021-04-19 18:34:46 +02:00
emitExpressionList ( node , elements , ListFormat . ArrayLiteralExpressionElements | preferNewLine , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
function emitObjectLiteralExpression ( node : ObjectLiteralExpression ) {
forEach ( node . properties , generateMemberNames ) ;
const indentedFlag = getEmitFlags ( node ) & EmitFlags . Indented ;
if ( indentedFlag ) {
increaseIndent ( ) ;
}
const preferNewLine = node . multiLine ? ListFormat.PreferNewLine : ListFormat.None ;
const allowTrailingComma = currentSourceFile ! . languageVersion >= ScriptTarget . ES5 && ! isJsonSourceFile ( currentSourceFile ! ) ? ListFormat.AllowTrailingComma : ListFormat.None ;
emitList ( node , node . properties , ListFormat . ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine ) ;
if ( indentedFlag ) {
decreaseIndent ( ) ;
}
}
function emitPropertyAccessExpression ( node : PropertyAccessExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-02-26 08:01:41 +01:00
const token = node . questionDotToken || setTextRangePosEnd ( factory . createToken ( SyntaxKind . DotToken ) as DotToken , node . expression . end , node . name . pos ) ;
const linesBeforeDot = getLinesBetweenNodes ( node , node . expression , token ) ;
const linesAfterDot = getLinesBetweenNodes ( node , token , node . name ) ;
writeLinesAndIndent ( linesBeforeDot , /*writeSpaceIfNotIndenting*/ false ) ;
const shouldEmitDotDot =
token . kind !== SyntaxKind . QuestionDotToken &&
mayNeedDotDotForPropertyAccess ( node . expression ) &&
! writer . hasTrailingComment ( ) &&
! writer . hasTrailingWhitespace ( ) ;
if ( shouldEmitDotDot ) {
writePunctuation ( "." ) ;
}
if ( node . questionDotToken ) {
emit ( token ) ;
}
else {
emitTokenWithComment ( token . kind , node . expression . end , writePunctuation , node ) ;
}
writeLinesAndIndent ( linesAfterDot , /*writeSpaceIfNotIndenting*/ false ) ;
emit ( node . name ) ;
decreaseIndentIf ( linesBeforeDot , linesAfterDot ) ;
}
// 1..toString is a valid property access, emit a dot after the literal
// Also emit a dot if expression is a integer const enum value - it will appear in generated code as numeric literal
function mayNeedDotDotForPropertyAccess ( expression : Expression ) {
expression = skipPartiallyEmittedExpressions ( expression ) ;
if ( isNumericLiteral ( expression ) ) {
// check if numeric literal is a decimal literal that was originally written with a dot
2021-05-18 15:20:57 +02:00
const text = getLiteralTextOfNode ( expression as LiteralExpression , /*neverAsciiEscape*/ true , /*jsxAttributeEscape*/ false ) ;
2021-02-26 08:01:41 +01:00
// If he number will be printed verbatim and it doesn't already contain a dot, add one
// if the expression doesn't have any comments that will be emitted.
return ! expression . numericLiteralFlags && ! stringContains ( text , tokenToString ( SyntaxKind . DotToken ) ! ) ;
}
else if ( isAccessExpression ( expression ) ) {
// check if constant enum value is integer
const constantValue = getConstantValue ( expression ) ;
// isFinite handles cases when constantValue is undefined
return typeof constantValue === "number" && isFinite ( constantValue )
&& Math . floor ( constantValue ) === constantValue ;
}
}
function emitElementAccessExpression ( node : ElementAccessExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-02-26 08:01:41 +01:00
emit ( node . questionDotToken ) ;
emitTokenWithComment ( SyntaxKind . OpenBracketToken , node . expression . end , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . argumentExpression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseBracketToken , node . argumentExpression . end , writePunctuation , node ) ;
}
function emitCallExpression ( node : CallExpression ) {
2021-06-22 04:51:13 +02:00
const indirectCall = getEmitFlags ( node ) & EmitFlags . IndirectCall ;
if ( indirectCall ) {
writePunctuation ( "(" ) ;
writeLiteral ( "0" ) ;
writePunctuation ( "," ) ;
writeSpace ( ) ;
}
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-06-22 04:51:13 +02:00
if ( indirectCall ) {
writePunctuation ( ")" ) ;
}
2021-02-26 08:01:41 +01:00
emit ( node . questionDotToken ) ;
emitTypeArguments ( node , node . typeArguments ) ;
2021-04-19 18:34:46 +02:00
emitExpressionList ( node , node . arguments , ListFormat . CallExpressionArguments , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
function emitNewExpression ( node : NewExpression ) {
emitTokenWithComment ( SyntaxKind . NewKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionOfNew ) ;
2021-02-26 08:01:41 +01:00
emitTypeArguments ( node , node . typeArguments ) ;
2021-04-19 18:34:46 +02:00
emitExpressionList ( node , node . arguments , ListFormat . NewExpressionArguments , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
function emitTaggedTemplateExpression ( node : TaggedTemplateExpression ) {
2021-06-22 04:51:13 +02:00
const indirectCall = getEmitFlags ( node ) & EmitFlags . IndirectCall ;
if ( indirectCall ) {
writePunctuation ( "(" ) ;
writeLiteral ( "0" ) ;
writePunctuation ( "," ) ;
writeSpace ( ) ;
}
2021-04-19 18:34:46 +02:00
emitExpression ( node . tag , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-06-22 04:51:13 +02:00
if ( indirectCall ) {
writePunctuation ( ")" ) ;
}
2021-02-26 08:01:41 +01:00
emitTypeArguments ( node , node . typeArguments ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . template ) ;
2021-02-26 08:01:41 +01:00
}
function emitTypeAssertionExpression ( node : TypeAssertion ) {
writePunctuation ( "<" ) ;
emit ( node . type ) ;
writePunctuation ( ">" ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function emitParenthesizedExpression ( node : ParenthesizedExpression ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . OpenParenToken , node . pos , writePunctuation , node ) ;
const indented = writeLineSeparatorsAndIndentBefore ( node . expression , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , /*parenthesizerRules*/ undefined ) ;
2021-02-26 08:01:41 +01:00
writeLineSeparatorsAfter ( node . expression , node ) ;
decreaseIndentIf ( indented ) ;
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression ? node.expression.end : openParenPos , writePunctuation , node ) ;
}
function emitFunctionExpression ( node : FunctionExpression ) {
generateNameIfNeeded ( node . name ) ;
emitFunctionDeclarationOrExpression ( node ) ;
}
function emitArrowFunction ( node : ArrowFunction ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
emitSignatureAndBody ( node , emitArrowFunctionHead ) ;
}
function emitArrowFunctionHead ( node : ArrowFunction ) {
emitTypeParameters ( node , node . typeParameters ) ;
emitParametersForArrow ( node , node . parameters ) ;
emitTypeAnnotation ( node . type ) ;
writeSpace ( ) ;
emit ( node . equalsGreaterThanToken ) ;
}
function emitDeleteExpression ( node : DeleteExpression ) {
emitTokenWithComment ( SyntaxKind . DeleteKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function emitTypeOfExpression ( node : TypeOfExpression ) {
emitTokenWithComment ( SyntaxKind . TypeOfKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function emitVoidExpression ( node : VoidExpression ) {
emitTokenWithComment ( SyntaxKind . VoidKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function emitAwaitExpression ( node : AwaitExpression ) {
emitTokenWithComment ( SyntaxKind . AwaitKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function emitPrefixUnaryExpression ( node : PrefixUnaryExpression ) {
writeTokenText ( node . operator , writeOperator ) ;
if ( shouldEmitWhitespaceBeforeOperand ( node ) ) {
writeSpace ( ) ;
}
2021-04-19 18:34:46 +02:00
emitExpression ( node . operand , parenthesizer . parenthesizeOperandOfPrefixUnary ) ;
2021-02-26 08:01:41 +01:00
}
function shouldEmitWhitespaceBeforeOperand ( node : PrefixUnaryExpression ) {
// In some cases, we need to emit a space between the operator and the operand. One obvious case
// is when the operator is an identifier, like delete or typeof. We also need to do this for plus
// and minus expressions in certain cases. Specifically, consider the following two cases (parens
// are just for clarity of exposition, and not part of the source code):
//
// (+(+1))
// (+(++1))
//
// We need to emit a space in both cases. In the first case, the absence of a space will make
// the resulting expression a prefix increment operation. And in the second, it will make the resulting
// expression a prefix increment whose operand is a plus expression - (++(+x))
// The same is true of minus of course.
const operand = node . operand ;
return operand . kind === SyntaxKind . PrefixUnaryExpression
2021-05-18 15:20:57 +02:00
&& ( ( node . operator === SyntaxKind . PlusToken && ( ( operand as PrefixUnaryExpression ) . operator === SyntaxKind . PlusToken || ( operand as PrefixUnaryExpression ) . operator === SyntaxKind . PlusPlusToken ) )
|| ( node . operator === SyntaxKind . MinusToken && ( ( operand as PrefixUnaryExpression ) . operator === SyntaxKind . MinusToken || ( operand as PrefixUnaryExpression ) . operator === SyntaxKind . MinusMinusToken ) ) ) ;
2021-02-26 08:01:41 +01:00
}
function emitPostfixUnaryExpression ( node : PostfixUnaryExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . operand , parenthesizer . parenthesizeOperandOfPostfixUnary ) ;
2021-02-26 08:01:41 +01:00
writeTokenText ( node . operator , writeOperator ) ;
}
function createEmitBinaryExpression() {
interface WorkArea {
stackIndex : number ;
preserveSourceNewlinesStack : ( boolean | undefined ) [ ] ;
containerPosStack : number [ ] ;
containerEndStack : number [ ] ;
declarationListContainerEndStack : number [ ] ;
shouldEmitCommentsStack : boolean [ ] ;
shouldEmitSourceMapsStack : boolean [ ] ;
}
2021-04-19 18:34:46 +02:00
return createBinaryExpressionTrampoline ( onEnter , onLeft , onOperator , onRight , onExit , /*foldState*/ undefined ) ;
2021-02-26 08:01:41 +01:00
function onEnter ( node : BinaryExpression , state : WorkArea | undefined ) {
if ( state ) {
state . stackIndex ++ ;
state . preserveSourceNewlinesStack [ state . stackIndex ] = preserveSourceNewlines ;
state . containerPosStack [ state . stackIndex ] = containerPos ;
state . containerEndStack [ state . stackIndex ] = containerEnd ;
state . declarationListContainerEndStack [ state . stackIndex ] = declarationListContainerEnd ;
const emitComments = state . shouldEmitCommentsStack [ state . stackIndex ] = shouldEmitComments ( node ) ;
const emitSourceMaps = state . shouldEmitSourceMapsStack [ state . stackIndex ] = shouldEmitSourceMaps ( node ) ;
2021-04-19 18:34:46 +02:00
onBeforeEmitNode ? . ( node ) ;
if ( emitComments ) emitCommentsBeforeNode ( node ) ;
if ( emitSourceMaps ) emitSourceMapsBeforeNode ( node ) ;
beforeEmitNode ( node ) ;
2021-02-26 08:01:41 +01:00
}
else {
state = {
stackIndex : 0 ,
preserveSourceNewlinesStack : [ undefined ] ,
containerPosStack : [ - 1 ] ,
containerEndStack : [ - 1 ] ,
declarationListContainerEndStack : [ - 1 ] ,
shouldEmitCommentsStack : [ false ] ,
shouldEmitSourceMapsStack : [ false ] ,
} ;
}
return state ;
}
2021-04-19 18:34:46 +02:00
function onLeft ( next : Expression , _workArea : WorkArea , parent : BinaryExpression ) {
return maybeEmitExpression ( next , parent , "left" ) ;
}
2021-02-26 08:01:41 +01:00
function onOperator ( operatorToken : BinaryOperatorToken , _state : WorkArea , node : BinaryExpression ) {
const isCommaOperator = operatorToken . kind !== SyntaxKind . CommaToken ;
const linesBeforeOperator = getLinesBetweenNodes ( node , node . left , operatorToken ) ;
const linesAfterOperator = getLinesBetweenNodes ( node , operatorToken , node . right ) ;
writeLinesAndIndent ( linesBeforeOperator , isCommaOperator ) ;
emitLeadingCommentsOfPosition ( operatorToken . pos ) ;
writeTokenNode ( operatorToken , operatorToken . kind === SyntaxKind . InKeyword ? writeKeyword : writeOperator ) ;
emitTrailingCommentsOfPosition ( operatorToken . end , /*prefixSpace*/ true ) ; // Binary operators should have a space before the comment starts
writeLinesAndIndent ( linesAfterOperator , /*writeSpaceIfNotIndenting*/ true ) ;
}
2021-04-19 18:34:46 +02:00
function onRight ( next : Expression , _workArea : WorkArea , parent : BinaryExpression ) {
return maybeEmitExpression ( next , parent , "right" ) ;
}
2021-02-26 08:01:41 +01:00
function onExit ( node : BinaryExpression , state : WorkArea ) {
const linesBeforeOperator = getLinesBetweenNodes ( node , node . left , node . operatorToken ) ;
const linesAfterOperator = getLinesBetweenNodes ( node , node . operatorToken , node . right ) ;
decreaseIndentIf ( linesBeforeOperator , linesAfterOperator ) ;
if ( state . stackIndex > 0 ) {
const savedPreserveSourceNewlines = state . preserveSourceNewlinesStack [ state . stackIndex ] ;
const savedContainerPos = state . containerPosStack [ state . stackIndex ] ;
const savedContainerEnd = state . containerEndStack [ state . stackIndex ] ;
const savedDeclarationListContainerEnd = state . declarationListContainerEndStack [ state . stackIndex ] ;
const shouldEmitComments = state . shouldEmitCommentsStack [ state . stackIndex ] ;
const shouldEmitSourceMaps = state . shouldEmitSourceMapsStack [ state . stackIndex ] ;
2021-04-19 18:34:46 +02:00
afterEmitNode ( savedPreserveSourceNewlines ) ;
if ( shouldEmitSourceMaps ) emitSourceMapsAfterNode ( node ) ;
if ( shouldEmitComments ) emitCommentsAfterNode ( node , savedContainerPos , savedContainerEnd , savedDeclarationListContainerEnd ) ;
onAfterEmitNode ? . ( node ) ;
2021-02-26 08:01:41 +01:00
state . stackIndex -- ;
}
}
2021-04-19 18:34:46 +02:00
function maybeEmitExpression ( next : Expression , parent : BinaryExpression , side : "left" | "right" ) {
const parenthesizerRule = side === "left" ?
parenthesizer . getParenthesizeLeftSideOfBinaryForOperator ( parent . operatorToken . kind ) :
parenthesizer . getParenthesizeRightSideOfBinaryForOperator ( parent . operatorToken . kind ) ;
let pipelinePhase = getPipelinePhase ( PipelinePhase . Notification , EmitHint . Expression , next ) ;
if ( pipelinePhase === pipelineEmitWithSubstitution ) {
Debug . assertIsDefined ( lastSubstitution ) ;
next = parenthesizerRule ( cast ( lastSubstitution , isExpression ) ) ;
pipelinePhase = getNextPipelinePhase ( PipelinePhase . Substitution , EmitHint . Expression , next ) ;
lastSubstitution = undefined ;
}
if ( pipelinePhase === pipelineEmitWithComments ||
pipelinePhase === pipelineEmitWithSourceMaps ||
pipelinePhase === pipelineEmitWithHint ) {
if ( isBinaryExpression ( next ) ) {
return next ;
}
2021-02-26 08:01:41 +01:00
}
2021-04-19 18:34:46 +02:00
currentParenthesizerRule = parenthesizerRule ;
pipelinePhase ( EmitHint . Expression , next ) ;
2021-02-26 08:01:41 +01:00
}
2016-11-11 00:20:29 +01:00
}
2021-02-26 08:01:41 +01:00
function emitConditionalExpression ( node : ConditionalExpression ) {
const linesBeforeQuestion = getLinesBetweenNodes ( node , node . condition , node . questionToken ) ;
const linesAfterQuestion = getLinesBetweenNodes ( node , node . questionToken , node . whenTrue ) ;
const linesBeforeColon = getLinesBetweenNodes ( node , node . whenTrue , node . colonToken ) ;
const linesAfterColon = getLinesBetweenNodes ( node , node . colonToken , node . whenFalse ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . condition , parenthesizer . parenthesizeConditionOfConditionalExpression ) ;
2021-02-26 08:01:41 +01:00
writeLinesAndIndent ( linesBeforeQuestion , /*writeSpaceIfNotIndenting*/ true ) ;
emit ( node . questionToken ) ;
writeLinesAndIndent ( linesAfterQuestion , /*writeSpaceIfNotIndenting*/ true ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . whenTrue , parenthesizer . parenthesizeBranchOfConditionalExpression ) ;
2021-02-26 08:01:41 +01:00
decreaseIndentIf ( linesBeforeQuestion , linesAfterQuestion ) ;
writeLinesAndIndent ( linesBeforeColon , /*writeSpaceIfNotIndenting*/ true ) ;
emit ( node . colonToken ) ;
writeLinesAndIndent ( linesAfterColon , /*writeSpaceIfNotIndenting*/ true ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . whenFalse , parenthesizer . parenthesizeBranchOfConditionalExpression ) ;
2021-02-26 08:01:41 +01:00
decreaseIndentIf ( linesBeforeColon , linesAfterColon ) ;
2016-08-02 20:45:56 +02:00
}
2014-10-11 01:44:14 +02:00
2021-02-26 08:01:41 +01:00
function emitTemplateExpression ( node : TemplateExpression ) {
2020-09-10 05:23:22 +02:00
emit ( node . head ) ;
emitList ( node , node . templateSpans , ListFormat . TemplateExpressionSpans ) ;
}
2021-02-26 08:01:41 +01:00
function emitYieldExpression ( node : YieldExpression ) {
emitTokenWithComment ( SyntaxKind . YieldKeyword , node . pos , writeKeyword , node ) ;
emit ( node . asteriskToken ) ;
2021-04-19 18:34:46 +02:00
emitExpressionWithLeadingSpace ( node . expression , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2018-04-02 19:18:23 +02:00
}
2021-04-19 18:34:46 +02:00
function emitSpreadElement ( node : SpreadElement ) {
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . DotDotDotToken , node . pos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
2015-04-03 02:23:25 +02:00
2021-02-26 08:01:41 +01:00
function emitClassExpression ( node : ClassExpression ) {
generateNameIfNeeded ( node . name ) ;
emitClassDeclarationOrExpression ( node ) ;
2016-06-07 19:32:03 +02:00
}
2014-08-22 02:17:02 +02:00
2021-02-26 08:01:41 +01:00
function emitExpressionWithTypeArguments ( node : ExpressionWithTypeArguments ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-02-26 08:01:41 +01:00
emitTypeArguments ( node , node . typeArguments ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-03 02:23:25 +02:00
2021-02-26 08:01:41 +01:00
function emitAsExpression ( node : AsExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , /*parenthesizerRules*/ undefined ) ;
2021-02-26 08:01:41 +01:00
if ( node . type ) {
writeSpace ( ) ;
writeKeyword ( "as" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . type ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
}
function emitNonNullExpression ( node : NonNullExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeLeftSideOfAccess ) ;
2021-02-26 08:01:41 +01:00
writeOperator ( "!" ) ;
}
function emitMetaProperty ( node : MetaProperty ) {
writeToken ( node . keywordToken , node . pos , writePunctuation ) ;
writePunctuation ( "." ) ;
2016-06-07 19:32:03 +02:00
emit ( node . name ) ;
}
2016-02-04 23:18:23 +01:00
2016-06-07 19:32:03 +02:00
//
2021-02-26 08:01:41 +01:00
// Misc
2016-06-07 19:32:03 +02:00
//
2015-03-10 20:12:41 +01:00
2021-02-26 08:01:41 +01:00
function emitTemplateSpan ( node : TemplateSpan ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emit ( node . literal ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-31 22:23:46 +02:00
2021-02-26 08:01:41 +01:00
//
// Statements
//
2018-05-02 22:34:14 +02:00
2021-02-26 08:01:41 +01:00
function emitBlock ( node : Block ) {
emitBlockStatements ( node , /*forceSingleLine*/ ! node . multiLine && isEmptyBlock ( node ) ) ;
}
2015-03-23 22:09:38 +01:00
2021-02-26 08:01:41 +01:00
function emitBlockStatements ( node : BlockLike , forceSingleLine : boolean ) {
emitTokenWithComment ( SyntaxKind . OpenBraceToken , node . pos , writePunctuation , /*contextNode*/ node ) ;
const format = forceSingleLine || getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat.SingleLineBlockStatements : ListFormat.MultiLineBlockStatements ;
emitList ( node , node . statements , format ) ;
emitTokenWithComment ( SyntaxKind . CloseBraceToken , node . statements . end , writePunctuation , /*contextNode*/ node , /*indentLeading*/ ! ! ( format & ListFormat . MultiLine ) ) ;
}
2015-04-03 02:23:25 +02:00
2021-02-26 08:01:41 +01:00
function emitVariableStatement ( node : VariableStatement ) {
emitModifiers ( node , node . modifiers ) ;
emit ( node . declarationList ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2014-08-22 02:17:02 +02:00
2021-02-26 08:01:41 +01:00
function emitEmptyStatement ( isEmbeddedStatement : boolean ) {
// While most trailing semicolons are possibly insignificant, an embedded "empty"
// statement is significant and cannot be elided by a trailing-semicolon-omitting writer.
if ( isEmbeddedStatement ) {
writePunctuation ( ";" ) ;
}
else {
writeTrailingSemicolon ( ) ;
}
}
2016-02-23 01:10:32 +01:00
2021-02-26 08:01:41 +01:00
function emitExpressionStatement ( node : ExpressionStatement ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionOfExpressionStatement ) ;
2021-02-26 08:01:41 +01:00
// Emit semicolon in non json files
// or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
if ( ! isJsonSourceFile ( currentSourceFile ! ) || nodeIsSynthesized ( node . expression ) ) {
writeTrailingSemicolon ( ) ;
}
}
2019-09-30 21:33:28 +02:00
2021-02-26 08:01:41 +01:00
function emitIfStatement ( node : IfStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . IfKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
emitEmbeddedStatement ( node , node . thenStatement ) ;
if ( node . elseStatement ) {
writeLineOrSpace ( node , node . thenStatement , node . elseStatement ) ;
emitTokenWithComment ( SyntaxKind . ElseKeyword , node . thenStatement . end , writeKeyword , node ) ;
if ( node . elseStatement . kind === SyntaxKind . IfStatement ) {
writeSpace ( ) ;
emit ( node . elseStatement ) ;
}
else {
emitEmbeddedStatement ( node , node . elseStatement ) ;
}
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2021-02-26 08:01:41 +01:00
}
2016-09-27 02:53:46 +02:00
2021-02-26 08:01:41 +01:00
function emitWhileClause ( node : WhileStatement | DoStatement , startPos : number ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . WhileKeyword , startPos , writeKeyword , node ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
}
function emitDoStatement ( node : DoStatement ) {
emitTokenWithComment ( SyntaxKind . DoKeyword , node . pos , writeKeyword , node ) ;
emitEmbeddedStatement ( node , node . statement ) ;
if ( isBlock ( node . statement ) && ! preserveSourceNewlines ) {
writeSpace ( ) ;
2020-02-25 18:07:01 +01:00
}
else {
2021-02-26 08:01:41 +01:00
writeLineOrSpace ( node , node . statement , node . expression ) ;
2020-02-25 18:07:01 +01:00
}
2021-02-26 08:01:41 +01:00
emitWhileClause ( node , node . statement . end ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-12 18:27:46 +01:00
2021-02-26 08:01:41 +01:00
function emitWhileStatement ( node : WhileStatement ) {
emitWhileClause ( node , node . pos ) ;
emitEmbeddedStatement ( node , node . statement ) ;
}
function emitForStatement ( node : ForStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . ForKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
let pos = emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , /*contextNode*/ node ) ;
emitForBinding ( node . initializer ) ;
pos = emitTokenWithComment ( SyntaxKind . SemicolonToken , node . initializer ? node.initializer.end : pos , writePunctuation , node ) ;
emitExpressionWithLeadingSpace ( node . condition ) ;
pos = emitTokenWithComment ( SyntaxKind . SemicolonToken , node . condition ? node.condition.end : pos , writePunctuation , node ) ;
emitExpressionWithLeadingSpace ( node . incrementor ) ;
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . incrementor ? node.incrementor.end : pos , writePunctuation , node ) ;
emitEmbeddedStatement ( node , node . statement ) ;
}
function emitForInStatement ( node : ForInStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . ForKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
emitForBinding ( node . initializer ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . InKeyword , node . initializer . end , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
emitEmbeddedStatement ( node , node . statement ) ;
}
function emitForOfStatement ( node : ForOfStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . ForKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
emitWithTrailingSpace ( node . awaitModifier ) ;
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
emitForBinding ( node . initializer ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . OfKeyword , node . initializer . end , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
emitEmbeddedStatement ( node , node . statement ) ;
}
function emitForBinding ( node : VariableDeclarationList | Expression | undefined ) {
if ( node !== undefined ) {
if ( node . kind === SyntaxKind . VariableDeclarationList ) {
emit ( node ) ;
}
else {
2021-04-19 18:34:46 +02:00
emitExpression ( node ) ;
2021-02-26 08:01:41 +01:00
}
}
}
function emitContinueStatement ( node : ContinueStatement ) {
emitTokenWithComment ( SyntaxKind . ContinueKeyword , node . pos , writeKeyword , node ) ;
emitWithLeadingSpace ( node . label ) ;
writeTrailingSemicolon ( ) ;
}
function emitBreakStatement ( node : BreakStatement ) {
emitTokenWithComment ( SyntaxKind . BreakKeyword , node . pos , writeKeyword , node ) ;
emitWithLeadingSpace ( node . label ) ;
writeTrailingSemicolon ( ) ;
}
function emitTokenWithComment ( token : SyntaxKind , pos : number , writer : ( s : string ) = > void , contextNode : Node , indentLeading? : boolean ) {
const node = getParseTreeNode ( contextNode ) ;
const isSimilarNode = node && node . kind === contextNode . kind ;
const startPos = pos ;
if ( isSimilarNode && currentSourceFile ) {
pos = skipTrivia ( currentSourceFile . text , pos ) ;
2014-08-19 19:43:13 +02:00
}
2021-02-26 08:01:41 +01:00
if ( isSimilarNode && contextNode . pos !== startPos ) {
const needsIndent = indentLeading && currentSourceFile && ! positionsAreOnSameLine ( startPos , pos , currentSourceFile ) ;
if ( needsIndent ) {
increaseIndent ( ) ;
}
emitLeadingCommentsOfPosition ( startPos ) ;
if ( needsIndent ) {
decreaseIndent ( ) ;
}
}
pos = writeTokenText ( token , writer , pos ) ;
if ( isSimilarNode && contextNode . end !== pos ) {
const isJsxExprContext = contextNode . kind === SyntaxKind . JsxExpression ;
emitTrailingCommentsOfPosition ( pos , /*prefixSpace*/ ! isJsxExprContext , /*forceNoNewline*/ isJsxExprContext ) ;
2015-03-17 21:41:29 +01:00
}
2021-02-26 08:01:41 +01:00
return pos ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2021-02-26 08:01:41 +01:00
function emitReturnStatement ( node : ReturnStatement ) {
emitTokenWithComment ( SyntaxKind . ReturnKeyword , node . pos , writeKeyword , /*contextNode*/ node ) ;
emitExpressionWithLeadingSpace ( node . expression ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-24 22:16:52 +01:00
2021-02-26 08:01:41 +01:00
function emitWithStatement ( node : WithStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . WithKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
emitEmbeddedStatement ( node , node . statement ) ;
2016-06-07 19:32:03 +02:00
}
2016-01-28 01:13:51 +01:00
2021-02-26 08:01:41 +01:00
function emitSwitchStatement ( node : SwitchStatement ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . SwitchKeyword , node . pos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . expression . end , writePunctuation , node ) ;
writeSpace ( ) ;
emit ( node . caseBlock ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-02 02:58:28 +02:00
2021-02-26 08:01:41 +01:00
function emitLabeledStatement ( node : LabeledStatement ) {
emit ( node . label ) ;
emitTokenWithComment ( SyntaxKind . ColonToken , node . label . end , writePunctuation , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . statement ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-02 02:58:28 +02:00
2021-02-26 08:01:41 +01:00
function emitThrowStatement ( node : ThrowStatement ) {
emitTokenWithComment ( SyntaxKind . ThrowKeyword , node . pos , writeKeyword , node ) ;
emitExpressionWithLeadingSpace ( node . expression ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-24 22:16:52 +01:00
2021-02-26 08:01:41 +01:00
function emitTryStatement ( node : TryStatement ) {
emitTokenWithComment ( SyntaxKind . TryKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
emit ( node . tryBlock ) ;
if ( node . catchClause ) {
writeLineOrSpace ( node , node . tryBlock , node . catchClause ) ;
emit ( node . catchClause ) ;
}
if ( node . finallyBlock ) {
writeLineOrSpace ( node , node . catchClause || node . tryBlock , node . finallyBlock ) ;
emitTokenWithComment ( SyntaxKind . FinallyKeyword , ( node . catchClause || node . tryBlock ) . end , writeKeyword , node ) ;
writeSpace ( ) ;
emit ( node . finallyBlock ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-03-17 21:41:29 +01:00
2021-02-26 08:01:41 +01:00
function emitDebuggerStatement ( node : DebuggerStatement ) {
writeToken ( SyntaxKind . DebuggerKeyword , node . pos , writeKeyword ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-02 02:58:28 +02:00
2021-02-26 08:01:41 +01:00
//
// Declarations
//
2015-03-18 01:09:39 +01:00
2021-02-26 08:01:41 +01:00
function emitVariableDeclaration ( node : VariableDeclaration ) {
emit ( node . name ) ;
emit ( node . exclamationToken ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
emitTypeAnnotation ( node . type ) ;
2021-04-19 18:34:46 +02:00
emitInitializer ( node . initializer , node . type ? node.type.end : node.name.end , node , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-18 01:09:39 +01:00
2021-02-26 08:01:41 +01:00
function emitVariableDeclarationList ( node : VariableDeclarationList ) {
writeKeyword ( isLet ( node ) ? "let" : isVarConst ( node ) ? "const" : "var" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitList ( node , node . declarations , ListFormat . VariableDeclarationList ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitFunctionDeclaration ( node : FunctionDeclaration ) {
emitFunctionDeclarationOrExpression ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitFunctionDeclarationOrExpression ( node : FunctionDeclaration | FunctionExpression ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
writeKeyword ( "function" ) ;
emit ( node . asteriskToken ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitIdentifierName ( node . name ) ;
2021-02-26 08:01:41 +01:00
emitSignatureAndBody ( node , emitSignatureHead ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitSignatureAndBody ( node : FunctionLikeDeclaration , emitSignatureHead : ( node : SignatureDeclaration ) = > void ) {
const body = node . body ;
if ( body ) {
if ( isBlock ( body ) ) {
const indentedFlag = getEmitFlags ( node ) & EmitFlags . Indented ;
if ( indentedFlag ) {
increaseIndent ( ) ;
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
pushNameGenerationScope ( node ) ;
forEach ( node . parameters , generateNames ) ;
generateNames ( node . body ) ;
emitSignatureHead ( node ) ;
emitBlockFunctionBody ( body ) ;
popNameGenerationScope ( node ) ;
if ( indentedFlag ) {
decreaseIndent ( ) ;
}
}
else {
emitSignatureHead ( node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( body , parenthesizer . parenthesizeConciseBodyOfArrowFunction ) ;
2021-02-26 08:01:41 +01:00
}
}
else {
emitSignatureHead ( node ) ;
writeTrailingSemicolon ( ) ;
2015-06-19 19:32:10 +02:00
}
2015-07-27 13:52:57 +02:00
2016-06-07 19:32:03 +02:00
}
2015-07-17 00:13:31 +02:00
2021-02-26 08:01:41 +01:00
function emitSignatureHead ( node : FunctionDeclaration | FunctionExpression | MethodDeclaration | AccessorDeclaration | ConstructorDeclaration ) {
emitTypeParameters ( node , node . typeParameters ) ;
emitParameters ( node , node . parameters ) ;
emitTypeAnnotation ( node . type ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function shouldEmitBlockFunctionBodyOnSingleLine ( body : Block ) {
// We must emit a function body as a single-line body in the following case:
// * The body has NodeEmitFlags.SingleLine specified.
2020-01-25 01:29:55 +01:00
2021-02-26 08:01:41 +01:00
// We must emit a function body as a multi-line body in the following cases:
// * The body is explicitly marked as multi-line.
// * A non-synthesized body's start and end position are on different lines.
// * Any statement in the body starts on a new line.
2020-01-25 01:29:55 +01:00
2021-02-26 08:01:41 +01:00
if ( getEmitFlags ( body ) & EmitFlags . SingleLine ) {
return true ;
}
2020-01-25 01:29:55 +01:00
2021-02-26 08:01:41 +01:00
if ( body . multiLine ) {
return false ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
if ( ! nodeIsSynthesized ( body ) && ! rangeIsOnSingleLine ( body , currentSourceFile ! ) ) {
return false ;
}
2020-01-25 01:29:55 +01:00
2021-02-26 08:01:41 +01:00
if ( getLeadingLineTerminatorCount ( body , body . statements , ListFormat . PreserveLines )
|| getClosingLineTerminatorCount ( body , body . statements , ListFormat . PreserveLines ) ) {
return false ;
}
2020-01-25 01:29:55 +01:00
2021-02-26 08:01:41 +01:00
let previousStatement : Statement | undefined ;
for ( const statement of body . statements ) {
if ( getSeparatingLineTerminatorCount ( previousStatement , statement , ListFormat . PreserveLines ) > 0 ) {
return false ;
2020-01-25 01:29:55 +01:00
}
2021-02-26 08:01:41 +01:00
previousStatement = statement ;
2020-01-25 01:29:55 +01:00
}
2021-02-26 08:01:41 +01:00
return true ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitBlockFunctionBody ( body : Block ) {
onBeforeEmitNode ? . ( body ) ;
writeSpace ( ) ;
writePunctuation ( "{" ) ;
increaseIndent ( ) ;
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
const emitBlockFunctionBody = shouldEmitBlockFunctionBodyOnSingleLine ( body )
? emitBlockFunctionBodyOnSingleLine
: emitBlockFunctionBodyWorker ;
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
if ( emitBodyWithDetachedComments ) {
emitBodyWithDetachedComments ( body , body . statements , emitBlockFunctionBody ) ;
}
else {
emitBlockFunctionBody ( body ) ;
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
decreaseIndent ( ) ;
writeToken ( SyntaxKind . CloseBraceToken , body . statements . end , writePunctuation , body ) ;
onAfterEmitNode ? . ( body ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitBlockFunctionBodyOnSingleLine ( body : Block ) {
emitBlockFunctionBodyWorker ( body , /*emitBlockFunctionBodyOnSingleLine*/ true ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitBlockFunctionBodyWorker ( body : Block , emitBlockFunctionBodyOnSingleLine? : boolean ) {
// Emit all the prologue directives (like "use strict").
const statementOffset = emitPrologueDirectives ( body . statements ) ;
const pos = writer . getTextPos ( ) ;
emitHelpers ( body ) ;
if ( statementOffset === 0 && pos === writer . getTextPos ( ) && emitBlockFunctionBodyOnSingleLine ) {
decreaseIndent ( ) ;
emitList ( body , body . statements , ListFormat . SingleLineFunctionBodyStatements ) ;
increaseIndent ( ) ;
}
else {
2021-04-19 18:34:46 +02:00
emitList ( body , body . statements , ListFormat . MultiLineFunctionBodyStatements , /*parenthesizerRule*/ undefined , statementOffset ) ;
2021-02-26 08:01:41 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitClassDeclaration ( node : ClassDeclaration ) {
2016-06-07 19:32:03 +02:00
emitClassDeclarationOrExpression ( node ) ;
}
2021-02-26 08:01:41 +01:00
function emitClassDeclarationOrExpression ( node : ClassDeclaration | ClassExpression ) {
forEach ( node . members , generateMemberNames ) ;
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
writeKeyword ( "class" ) ;
if ( node . name ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitIdentifierName ( node . name ) ;
2015-06-19 19:32:10 +02:00
}
2016-12-09 02:31:18 +01:00
2021-02-26 08:01:41 +01:00
const indentedFlag = getEmitFlags ( node ) & EmitFlags . Indented ;
if ( indentedFlag ) {
increaseIndent ( ) ;
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
emitTypeParameters ( node , node . typeParameters ) ;
emitList ( node , node . heritageClauses , ListFormat . ClassHeritageClauses ) ;
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
writeSpace ( ) ;
writePunctuation ( "{" ) ;
emitList ( node , node . members , ListFormat . ClassMembers ) ;
writePunctuation ( "}" ) ;
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
if ( indentedFlag ) {
decreaseIndent ( ) ;
}
2016-06-07 19:32:03 +02:00
}
2014-08-22 23:40:47 +02:00
2021-02-26 08:01:41 +01:00
function emitInterfaceDeclaration ( node : InterfaceDeclaration ) {
emitDecorators ( node , node . decorators ) ;
emitModifiers ( node , node . modifiers ) ;
writeKeyword ( "interface" ) ;
writeSpace ( ) ;
emit ( node . name ) ;
emitTypeParameters ( node , node . typeParameters ) ;
emitList ( node , node . heritageClauses , ListFormat . HeritageClauses ) ;
writeSpace ( ) ;
writePunctuation ( "{" ) ;
emitList ( node , node . members , ListFormat . InterfaceMembers ) ;
writePunctuation ( "}" ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
function emitTypeAliasDeclaration ( node : TypeAliasDeclaration ) {
emitDecorators ( node , node . decorators ) ;
2016-06-07 19:32:03 +02:00
emitModifiers ( node , node . modifiers ) ;
2021-02-26 08:01:41 +01:00
writeKeyword ( "type" ) ;
writeSpace ( ) ;
emit ( node . name ) ;
emitTypeParameters ( node , node . typeParameters ) ;
writeSpace ( ) ;
writePunctuation ( "=" ) ;
writeSpace ( ) ;
emit ( node . type ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
function emitEnumDeclaration ( node : EnumDeclaration ) {
emitModifiers ( node , node . modifiers ) ;
writeKeyword ( "enum" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . name ) ;
2014-08-22 23:40:47 +02:00
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( "{" ) ;
emitList ( node , node . members , ListFormat . EnumMembers ) ;
writePunctuation ( "}" ) ;
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2021-02-26 08:01:41 +01:00
function emitModuleDeclaration ( node : ModuleDeclaration ) {
emitModifiers ( node , node . modifiers ) ;
if ( ~ node . flags & NodeFlags . GlobalAugmentation ) {
writeKeyword ( node . flags & NodeFlags . Namespace ? "namespace" : "module" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2014-07-18 23:40:47 +02:00
}
2021-02-26 08:01:41 +01:00
emit ( node . name ) ;
let body = node . body ;
if ( ! body ) return writeTrailingSemicolon ( ) ;
2021-03-25 22:46:16 +01:00
while ( body && isModuleDeclaration ( body ) ) {
2021-02-26 08:01:41 +01:00
writePunctuation ( "." ) ;
2021-03-25 22:46:16 +01:00
emit ( body . name ) ;
body = body . body ;
2014-07-18 23:40:47 +02:00
}
2014-07-16 19:49:11 +02:00
2021-02-26 08:01:41 +01:00
writeSpace ( ) ;
emit ( body ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2021-02-26 08:01:41 +01:00
function emitModuleBlock ( node : ModuleBlock ) {
pushNameGenerationScope ( node ) ;
forEach ( node . statements , generateNames ) ;
emitBlockStatements ( node , /*forceSingleLine*/ isEmptyBlock ( node ) ) ;
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
function emitCaseBlock ( node : CaseBlock ) {
emitTokenWithComment ( SyntaxKind . OpenBraceToken , node . pos , writePunctuation , node ) ;
emitList ( node , node . clauses , ListFormat . CaseBlockClauses ) ;
emitTokenWithComment ( SyntaxKind . CloseBraceToken , node . clauses . end , writePunctuation , node , /*indentLeading*/ true ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-13 22:57:26 +02:00
2021-02-26 08:01:41 +01:00
function emitImportEqualsDeclaration ( node : ImportEqualsDeclaration ) {
emitModifiers ( node , node . modifiers ) ;
emitTokenWithComment ( SyntaxKind . ImportKeyword , node . modifiers ? node.modifiers.end : node.pos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
if ( node . isTypeOnly ) {
emitTokenWithComment ( SyntaxKind . TypeKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
}
emit ( node . name ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . EqualsToken , node . name . end , writePunctuation , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitModuleReference ( node . module Reference ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-11-23 21:55:29 +01:00
2021-02-26 08:01:41 +01:00
function emitModuleReference ( node : ModuleReference ) {
if ( node . kind === SyntaxKind . Identifier ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node ) ;
2021-02-26 08:01:41 +01:00
}
else {
emit ( node ) ;
}
}
function emitImportDeclaration ( node : ImportDeclaration ) {
emitModifiers ( node , node . modifiers ) ;
emitTokenWithComment ( SyntaxKind . ImportKeyword , node . modifiers ? node.modifiers.end : node.pos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
if ( node . importClause ) {
emit ( node . importClause ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . FromKeyword , node . importClause . end , writeKeyword , node ) ;
writeSpace ( ) ;
}
2021-04-19 18:34:46 +02:00
emitExpression ( node . module Specifier ) ;
2021-02-26 08:01:41 +01:00
writeTrailingSemicolon ( ) ;
}
function emitImportClause ( node : ImportClause ) {
if ( node . isTypeOnly ) {
emitTokenWithComment ( SyntaxKind . TypeKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
}
emit ( node . name ) ;
if ( node . name && node . namedBindings ) {
emitTokenWithComment ( SyntaxKind . CommaToken , node . name . end , writePunctuation , node ) ;
writeSpace ( ) ;
}
emit ( node . namedBindings ) ;
}
function emitNamespaceImport ( node : NamespaceImport ) {
const asPos = emitTokenWithComment ( SyntaxKind . AsteriskToken , node . pos , writePunctuation , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . AsKeyword , asPos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . name ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2021-02-26 08:01:41 +01:00
function emitNamedImports ( node : NamedImports ) {
emitNamedImportsOrExports ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-13 22:57:26 +02:00
2021-02-26 08:01:41 +01:00
function emitImportSpecifier ( node : ImportSpecifier ) {
emitImportOrExportSpecifier ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-02-14 09:48:46 +01:00
2021-02-26 08:01:41 +01:00
function emitExportAssignment ( node : ExportAssignment ) {
const nextPos = emitTokenWithComment ( SyntaxKind . ExportKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
if ( node . isExportEquals ) {
emitTokenWithComment ( SyntaxKind . EqualsToken , nextPos , writeOperator , node ) ;
}
else {
emitTokenWithComment ( SyntaxKind . DefaultKeyword , nextPos , writeKeyword , node ) ;
}
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , node . isExportEquals ?
parenthesizer . getParenthesizeRightSideOfBinaryForOperator ( SyntaxKind . EqualsToken ) :
parenthesizer . parenthesizeExpressionOfExportDefault ) ;
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-02-14 09:48:46 +01:00
2021-02-26 08:01:41 +01:00
function emitExportDeclaration ( node : ExportDeclaration ) {
let nextPos = emitTokenWithComment ( SyntaxKind . ExportKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
if ( node . isTypeOnly ) {
nextPos = emitTokenWithComment ( SyntaxKind . TypeKeyword , nextPos , writeKeyword , node ) ;
writeSpace ( ) ;
2017-08-09 04:53:53 +02:00
}
2021-02-26 08:01:41 +01:00
if ( node . exportClause ) {
emit ( node . exportClause ) ;
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2021-02-26 08:01:41 +01:00
else {
nextPos = emitTokenWithComment ( SyntaxKind . AsteriskToken , nextPos , writePunctuation , node ) ;
}
if ( node . module Specifier ) {
writeSpace ( ) ;
const fromPos = node . exportClause ? node.exportClause.end : nextPos ;
emitTokenWithComment ( SyntaxKind . FromKeyword , fromPos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . module Specifier ) ;
2017-08-09 04:53:53 +02:00
}
2018-08-22 21:42:36 +02:00
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-10-11 10:12:26 +02:00
2021-02-26 08:01:41 +01:00
function emitNamespaceExportDeclaration ( node : NamespaceExportDeclaration ) {
let nextPos = emitTokenWithComment ( SyntaxKind . ExportKeyword , node . pos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
nextPos = emitTokenWithComment ( SyntaxKind . AsKeyword , nextPos , writeKeyword , node ) ;
writeSpace ( ) ;
nextPos = emitTokenWithComment ( SyntaxKind . NamespaceKeyword , nextPos , writeKeyword , node ) ;
writeSpace ( ) ;
emit ( node . name ) ;
writeTrailingSemicolon ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-10-01 00:45:23 +02:00
2021-02-26 08:01:41 +01:00
function emitNamespaceExport ( node : NamespaceExport ) {
const asPos = emitTokenWithComment ( SyntaxKind . AsteriskToken , node . pos , writePunctuation , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . AsKeyword , asPos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . name ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-17 00:39:14 +02:00
2021-02-26 08:01:41 +01:00
function emitNamedExports ( node : NamedExports ) {
emitNamedImportsOrExports ( node ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-17 00:39:14 +02:00
2021-02-26 08:01:41 +01:00
function emitExportSpecifier ( node : ExportSpecifier ) {
emitImportOrExportSpecifier ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-21 23:09:54 +01:00
2021-02-26 08:01:41 +01:00
function emitNamedImportsOrExports ( node : NamedImportsOrExports ) {
writePunctuation ( "{" ) ;
emitList ( node , node . elements , ListFormat . NamedImportsOrExportsElements ) ;
writePunctuation ( "}" ) ;
}
function emitImportOrExportSpecifier ( node : ImportOrExportSpecifier ) {
if ( node . propertyName ) {
emit ( node . propertyName ) ;
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . AsKeyword , node . propertyName . end , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2015-03-24 00:56:29 +01:00
}
2021-02-26 08:01:41 +01:00
emit ( node . name ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-22 17:10:10 +01:00
2016-06-07 19:32:03 +02:00
//
2021-02-26 08:01:41 +01:00
// Module references
2016-06-07 19:32:03 +02:00
//
2015-03-12 08:17:40 +01:00
2021-02-26 08:01:41 +01:00
function emitExternalModuleReference ( node : ExternalModuleReference ) {
writeKeyword ( "require" ) ;
writePunctuation ( "(" ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( ")" ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
//
// JSX
//
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function emitJsxElement ( node : JsxElement ) {
emit ( node . openingElement ) ;
emitList ( node , node . children , ListFormat . JsxElementOrFragmentChildren ) ;
emit ( node . closingElement ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-12 08:17:40 +01:00
2021-02-26 08:01:41 +01:00
function emitJsxSelfClosingElement ( node : JsxSelfClosingElement ) {
writePunctuation ( "<" ) ;
emitJsxTagName ( node . tagName ) ;
emitTypeArguments ( node , node . typeArguments ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( node . attributes ) ;
writePunctuation ( "/>" ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitJsxFragment ( node : JsxFragment ) {
emit ( node . openingFragment ) ;
emitList ( node , node . children , ListFormat . JsxElementOrFragmentChildren ) ;
emit ( node . closingFragment ) ;
2017-03-15 19:44:36 +01:00
}
2021-02-26 08:01:41 +01:00
function emitJsxOpeningElementOrFragment ( node : JsxOpeningElement | JsxOpeningFragment ) {
writePunctuation ( "<" ) ;
2016-06-15 02:59:44 +02:00
2021-02-26 08:01:41 +01:00
if ( isJsxOpeningElement ( node ) ) {
const indented = writeLineSeparatorsAndIndentBefore ( node . tagName , node ) ;
emitJsxTagName ( node . tagName ) ;
emitTypeArguments ( node , node . typeArguments ) ;
if ( node . attributes . properties && node . attributes . properties . length > 0 ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2015-03-12 08:17:40 +01:00
}
2021-02-26 08:01:41 +01:00
emit ( node . attributes ) ;
writeLineSeparatorsAfter ( node . attributes , node ) ;
decreaseIndentIf ( indented ) ;
2015-02-08 17:03:15 +01:00
}
2014-08-05 02:59:33 +02:00
2021-02-26 08:01:41 +01:00
writePunctuation ( ">" ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitJsxText ( node : JsxText ) {
writer . writeLiteral ( node . text ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-22 00:56:30 +02:00
2021-02-26 08:01:41 +01:00
function emitJsxClosingElementOrFragment ( node : JsxClosingElement | JsxClosingFragment ) {
writePunctuation ( "</" ) ;
if ( isJsxClosingElement ( node ) ) {
emitJsxTagName ( node . tagName ) ;
2015-02-13 03:05:02 +01:00
}
2021-02-26 08:01:41 +01:00
writePunctuation ( ">" ) ;
}
2015-02-13 03:05:02 +01:00
2021-02-26 08:01:41 +01:00
function emitJsxAttributes ( node : JsxAttributes ) {
emitList ( node , node . properties , ListFormat . JsxElementAttributes ) ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function emitJsxAttribute ( node : JsxAttribute ) {
emit ( node . name ) ;
emitNodeWithPrefix ( "=" , writePunctuation , node . initializer , emitJsxAttributeValue ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitJsxSpreadAttribute ( node : JsxSpreadAttribute ) {
writePunctuation ( "{..." ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( "}" ) ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function hasTrailingCommentsAtPosition ( pos : number ) {
let result = false ;
forEachTrailingCommentRange ( currentSourceFile ? . text || "" , pos + 1 , ( ) = > result = true ) ;
return result ;
}
2017-01-30 21:27:24 +01:00
2021-02-26 08:01:41 +01:00
function hasLeadingCommentsAtPosition ( pos : number ) {
let result = false ;
forEachLeadingCommentRange ( currentSourceFile ? . text || "" , pos + 1 , ( ) = > result = true ) ;
return result ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function hasCommentsAtPosition ( pos : number ) {
return hasTrailingCommentsAtPosition ( pos ) || hasLeadingCommentsAtPosition ( pos ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitJsxExpression ( node : JsxExpression ) {
if ( node . expression || ( ! commentsDisabled && ! nodeIsSynthesized ( node ) && hasCommentsAtPosition ( node . pos ) ) ) { // preserve empty expressions if they contain comments!
const isMultiline = currentSourceFile && ! nodeIsSynthesized ( node ) && getLineAndCharacterOfPosition ( currentSourceFile , node . pos ) . line !== getLineAndCharacterOfPosition ( currentSourceFile , node . end ) . line ;
if ( isMultiline ) {
writer . increaseIndent ( ) ;
}
const end = emitTokenWithComment ( SyntaxKind . OpenBraceToken , node . pos , writePunctuation , node ) ;
emit ( node . dotDotDotToken ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2021-02-26 08:01:41 +01:00
emitTokenWithComment ( SyntaxKind . CloseBraceToken , node . expression ? . end || end , writePunctuation , node ) ;
if ( isMultiline ) {
writer . decreaseIndent ( ) ;
}
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitJsxTagName ( node : JsxTagNameExpression ) {
if ( node . kind === SyntaxKind . Identifier ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node ) ;
2015-03-21 23:46:16 +01:00
}
2016-06-07 19:32:03 +02:00
else {
2021-02-26 08:01:41 +01:00
emit ( node ) ;
2015-04-10 21:10:38 +02:00
}
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
//
// Clauses
//
2018-05-02 22:34:14 +02:00
2021-02-26 08:01:41 +01:00
function emitCaseClause ( node : CaseClause ) {
emitTokenWithComment ( SyntaxKind . CaseKeyword , node . pos , writeKeyword , node ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
emitCaseOrDefaultClauseRest ( node , node . statements , node . expression . end ) ;
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function emitDefaultClause ( node : DefaultClause ) {
const pos = emitTokenWithComment ( SyntaxKind . DefaultKeyword , node . pos , writeKeyword , node ) ;
emitCaseOrDefaultClauseRest ( node , node . statements , pos ) ;
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function emitCaseOrDefaultClauseRest ( parentNode : Node , statements : NodeArray < Statement > , colonPos : number ) {
const emitAsSingleStatement =
statements . length === 1 &&
(
// treat synthesized nodes as located on the same line for emit purposes
nodeIsSynthesized ( parentNode ) ||
nodeIsSynthesized ( statements [ 0 ] ) ||
rangeStartPositionsAreOnSameLine ( parentNode , statements [ 0 ] , currentSourceFile ! )
) ;
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
let format = ListFormat . CaseOrDefaultClauseStatements ;
if ( emitAsSingleStatement ) {
writeToken ( SyntaxKind . ColonToken , colonPos , writePunctuation , parentNode ) ;
writeSpace ( ) ;
format &= ~ ( ListFormat . MultiLine | ListFormat . Indented ) ;
2015-04-10 21:10:38 +02:00
}
2021-02-26 08:01:41 +01:00
else {
emitTokenWithComment ( SyntaxKind . ColonToken , colonPos , writePunctuation , parentNode ) ;
}
emitList ( parentNode , statements , format ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitHeritageClause ( node : HeritageClause ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
writeTokenText ( node . token , writeKeyword ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitList ( node , node . types , ListFormat . HeritageClauseTypes ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitCatchClause ( node : CatchClause ) {
const openParenPos = emitTokenWithComment ( SyntaxKind . CatchKeyword , node . pos , writeKeyword , node ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
if ( node . variableDeclaration ) {
emitTokenWithComment ( SyntaxKind . OpenParenToken , openParenPos , writePunctuation , node ) ;
emit ( node . variableDeclaration ) ;
emitTokenWithComment ( SyntaxKind . CloseParenToken , node . variableDeclaration . end , writePunctuation , node ) ;
writeSpace ( ) ;
}
emit ( node . block ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
//
// Property assignments
//
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
2021-02-26 08:01:41 +01:00
function emitPropertyAssignment ( node : PropertyAssignment ) {
emit ( node . name ) ;
writePunctuation ( ":" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
// This is to ensure that we emit comment in the following case:
// For example:
// obj = {
// id: /*comment1*/ ()=>void
// }
// "comment1" is not considered to be leading comment for node.initializer
// but rather a trailing comment on the previous node.
const initializer = node . initializer ;
if ( ( getEmitFlags ( initializer ) & EmitFlags . NoLeadingComments ) === 0 ) {
const commentRange = getCommentRange ( initializer ) ;
emitTrailingCommentsOfPosition ( commentRange . pos ) ;
}
2021-04-19 18:34:46 +02:00
emitExpression ( initializer , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitShorthandPropertyAssignment ( node : ShorthandPropertyAssignment ) {
emit ( node . name ) ;
if ( node . objectAssignmentInitializer ) {
writeSpace ( ) ;
writePunctuation ( "=" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . objectAssignmentInitializer , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2017-09-21 21:15:27 +02:00
}
2021-02-26 08:01:41 +01:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitSpreadAssignment ( node : SpreadAssignment ) {
if ( node . expression ) {
emitTokenWithComment ( SyntaxKind . DotDotDotToken , node . pos , writePunctuation , node ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
}
//
// Enum
//
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitEnumMember ( node : EnumMember ) {
emit ( node . name ) ;
2021-04-19 18:34:46 +02:00
emitInitializer ( node . initializer , node . name . end , node , parenthesizer . parenthesizeExpressionForDisallowedComma ) ;
2021-02-26 08:01:41 +01:00
}
//
// JSDoc
//
function emitJSDoc ( node : JSDoc ) {
write ( "/**" ) ;
if ( node . comment ) {
2021-03-23 00:39:35 +01:00
const text = getTextOfJSDocComment ( node . comment ) ;
if ( text ) {
const lines = text . split ( /\r\n?|\n/g ) ;
for ( const line of lines ) {
writeLine ( ) ;
writeSpace ( ) ;
writePunctuation ( "*" ) ;
writeSpace ( ) ;
write ( line ) ;
}
2021-02-26 08:01:41 +01:00
}
}
if ( node . tags ) {
if ( node . tags . length === 1 && node . tags [ 0 ] . kind === SyntaxKind . JSDocTypeTag && ! node . comment ) {
writeSpace ( ) ;
emit ( node . tags [ 0 ] ) ;
}
else {
emitList ( node , node . tags , ListFormat . JSDocComment ) ;
}
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
write ( "*/" ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocSimpleTypedTag ( tag : JSDocTypeTag | JSDocThisTag | JSDocEnumTag | JSDocReturnTag ) {
emitJSDocTagName ( tag . tagName ) ;
emitJSDocTypeExpression ( tag . typeExpression ) ;
emitJSDocComment ( tag . comment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocSeeTag ( tag : JSDocSeeTag ) {
emitJSDocTagName ( tag . tagName ) ;
emit ( tag . name ) ;
emitJSDocComment ( tag . comment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocNameReference ( node : JSDocNameReference ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( "{" ) ;
2016-06-07 19:32:03 +02:00
emit ( node . name ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( "}" ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocHeritageTag ( tag : JSDocImplementsTag | JSDocAugmentsTag ) {
emitJSDocTagName ( tag . tagName ) ;
writeSpace ( ) ;
writePunctuation ( "{" ) ;
emit ( tag . class ) ;
writePunctuation ( "}" ) ;
emitJSDocComment ( tag . comment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 03:51:29 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocTemplateTag ( tag : JSDocTemplateTag ) {
emitJSDocTagName ( tag . tagName ) ;
emitJSDocTypeExpression ( tag . constraint ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emitList ( tag , tag . typeParameters , ListFormat . CommaListElements ) ;
emitJSDocComment ( tag . comment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocTypedefTag ( tag : JSDocTypedefTag ) {
emitJSDocTagName ( tag . tagName ) ;
if ( tag . typeExpression ) {
if ( tag . typeExpression . kind === SyntaxKind . JSDocTypeExpression ) {
emitJSDocTypeExpression ( tag . typeExpression ) ;
}
else {
writeSpace ( ) ;
writePunctuation ( "{" ) ;
write ( "Object" ) ;
if ( tag . typeExpression . isArrayType ) {
writePunctuation ( "[" ) ;
writePunctuation ( "]" ) ;
}
writePunctuation ( "}" ) ;
}
2020-01-03 23:39:32 +01:00
}
2021-02-26 08:01:41 +01:00
if ( tag . fullName ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
emit ( tag . fullName ) ;
}
emitJSDocComment ( tag . comment ) ;
if ( tag . typeExpression && tag . typeExpression . kind === SyntaxKind . JSDocTypeLiteral ) {
emitJSDocTypeLiteral ( tag . typeExpression ) ;
2016-06-07 19:32:03 +02:00
}
}
2015-04-29 05:17:55 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocCallbackTag ( tag : JSDocCallbackTag ) {
emitJSDocTagName ( tag . tagName ) ;
if ( tag . name ) {
writeSpace ( ) ;
emit ( tag . name ) ;
}
emitJSDocComment ( tag . comment ) ;
emitJSDocSignature ( tag . typeExpression ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocSimpleTag ( tag : JSDocTag ) {
emitJSDocTagName ( tag . tagName ) ;
emitJSDocComment ( tag . comment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 20:43:23 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocTypeLiteral ( lit : JSDocTypeLiteral ) {
emitList ( lit , factory . createNodeArray ( lit . jsDocPropertyTags ) , ListFormat . JSDocComment ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocSignature ( sig : JSDocSignature ) {
if ( sig . typeParameters ) {
emitList ( sig , factory . createNodeArray ( sig . typeParameters ) , ListFormat . JSDocComment ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
if ( sig . parameters ) {
emitList ( sig , factory . createNodeArray ( sig . parameters ) , ListFormat . JSDocComment ) ;
}
if ( sig . type ) {
writeLine ( ) ;
writeSpace ( ) ;
writePunctuation ( "*" ) ;
writeSpace ( ) ;
emit ( sig . type ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitJSDocPropertyLikeTag ( param : JSDocPropertyLikeTag ) {
emitJSDocTagName ( param . tagName ) ;
emitJSDocTypeExpression ( param . typeExpression ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
if ( param . isBracketed ) {
writePunctuation ( "[" ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
emit ( param . name ) ;
if ( param . isBracketed ) {
writePunctuation ( "]" ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
emitJSDocComment ( param . comment ) ;
}
function emitJSDocTagName ( tagName : Identifier ) {
writePunctuation ( "@" ) ;
emit ( tagName ) ;
}
2021-05-24 22:01:58 +02:00
function emitJSDocComment ( comment : string | NodeArray < JSDocComment > | undefined ) {
2021-03-23 00:39:35 +01:00
const text = getTextOfJSDocComment ( comment ) ;
if ( text ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-03-23 00:39:35 +01:00
write ( text ) ;
2021-02-26 08:01:41 +01:00
}
}
function emitJSDocTypeExpression ( typeExpression : JSDocTypeExpression | undefined ) {
if ( typeExpression ) {
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
writeSpace ( ) ;
2021-02-26 08:01:41 +01:00
writePunctuation ( "{" ) ;
emit ( typeExpression . type ) ;
writePunctuation ( "}" ) ;
2015-04-29 01:18:33 +02:00
}
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
//
// Top-level nodes
//
function emitSourceFile ( node : SourceFile ) {
writeLine ( ) ;
const statements = node . statements ;
if ( emitBodyWithDetachedComments ) {
// Emit detached comment if there are no prologue directives or if the first node is synthesized.
// The synthesized node will have no leading comment so some comments may be missed.
const shouldEmitDetachedComment = statements . length === 0 ||
! isPrologueDirective ( statements [ 0 ] ) ||
nodeIsSynthesized ( statements [ 0 ] ) ;
if ( shouldEmitDetachedComment ) {
emitBodyWithDetachedComments ( node , statements , emitSourceFileWorker ) ;
return ;
}
}
emitSourceFileWorker ( node ) ;
2017-05-23 20:07:34 +02:00
}
2021-02-26 08:01:41 +01:00
function emitSyntheticTripleSlashReferencesIfNeeded ( node : Bundle ) {
emitTripleSlashDirectives ( ! ! node . hasNoDefaultLib , node . syntheticFileReferences || [ ] , node . syntheticTypeReferences || [ ] , node . syntheticLibReferences || [ ] ) ;
for ( const prepend of node . prepends ) {
if ( isUnparsedSource ( prepend ) && prepend . syntheticReferences ) {
for ( const ref of prepend . syntheticReferences ) {
emit ( ref ) ;
writeLine ( ) ;
}
}
}
2019-12-21 01:00:20 +01:00
}
2021-02-26 08:01:41 +01:00
function emitTripleSlashDirectivesIfNeeded ( node : SourceFile ) {
if ( node . isDeclarationFile ) emitTripleSlashDirectives ( node . hasNoDefaultLib , node . referencedFiles , node . typeReferenceDirectives , node . libReferenceDirectives ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function emitTripleSlashDirectives ( hasNoDefaultLib : boolean , files : readonly FileReference [ ] , types : readonly FileReference [ ] , libs : readonly FileReference [ ] ) {
if ( hasNoDefaultLib ) {
const pos = writer . getTextPos ( ) ;
writeComment ( ` /// <reference no-default-lib="true"/> ` ) ;
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.NoDefaultLib } ) ;
writeLine ( ) ;
}
if ( currentSourceFile && currentSourceFile . module Name ) {
writeComment ( ` /// <amd-module name=" ${ currentSourceFile . module Name } " /> ` ) ;
writeLine ( ) ;
}
if ( currentSourceFile && currentSourceFile . amdDependencies ) {
for ( const dep of currentSourceFile . amdDependencies ) {
if ( dep . name ) {
writeComment ( ` /// <amd-dependency name=" ${ dep . name } " path=" ${ dep . path } " /> ` ) ;
}
else {
writeComment ( ` /// <amd-dependency path=" ${ dep . path } " /> ` ) ;
}
writeLine ( ) ;
}
}
for ( const directive of files ) {
const pos = writer . getTextPos ( ) ;
writeComment ( ` /// <reference path=" ${ directive . fileName } " /> ` ) ;
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.Reference , data : directive.fileName } ) ;
writeLine ( ) ;
}
for ( const directive of types ) {
const pos = writer . getTextPos ( ) ;
writeComment ( ` /// <reference types=" ${ directive . fileName } " /> ` ) ;
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.Type , data : directive.fileName } ) ;
writeLine ( ) ;
}
for ( const directive of libs ) {
const pos = writer . getTextPos ( ) ;
writeComment ( ` /// <reference lib=" ${ directive . fileName } " /> ` ) ;
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.Lib , data : directive.fileName } ) ;
writeLine ( ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function emitSourceFileWorker ( node : SourceFile ) {
const statements = node . statements ;
pushNameGenerationScope ( node ) ;
forEach ( node . statements , generateNames ) ;
emitHelpers ( node ) ;
const index = findIndex ( statements , statement = > ! isPrologueDirective ( statement ) ) ;
emitTripleSlashDirectivesIfNeeded ( node ) ;
2021-04-19 18:34:46 +02:00
emitList ( node , statements , ListFormat . MultiLine , /*parenthesizerRule*/ undefined , index === - 1 ? statements.length : index ) ;
2021-02-26 08:01:41 +01:00
popNameGenerationScope ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-05-11 09:07:49 +02:00
2021-02-26 08:01:41 +01:00
// Transformation nodes
2015-05-11 09:07:49 +02:00
2021-02-26 08:01:41 +01:00
function emitPartiallyEmittedExpression ( node : PartiallyEmittedExpression ) {
2021-04-19 18:34:46 +02:00
emitExpression ( node . expression ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitCommaList ( node : CommaListExpression ) {
2021-04-19 18:34:46 +02:00
emitExpressionList ( node , node . elements , ListFormat . CommaListElements , /*parenthesizerRule*/ undefined ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
/ * *
* Emits any prologue directives at the start of a Statement list , returning the
* number of prologue directives written to the output .
* /
function emitPrologueDirectives ( statements : readonly Node [ ] , sourceFile? : SourceFile , seenPrologueDirectives? : Set < string > , recordBundleFileSection? : true ) : number {
let needsToSetSourceFile = ! ! sourceFile ;
for ( let i = 0 ; i < statements . length ; i ++ ) {
const statement = statements [ i ] ;
if ( isPrologueDirective ( statement ) ) {
const shouldEmitPrologueDirective = seenPrologueDirectives ? ! seenPrologueDirectives . has ( statement . expression . text ) : true ;
if ( shouldEmitPrologueDirective ) {
if ( needsToSetSourceFile ) {
needsToSetSourceFile = false ;
setSourceFile ( sourceFile ) ;
}
writeLine ( ) ;
const pos = writer . getTextPos ( ) ;
emit ( statement ) ;
if ( recordBundleFileSection && bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.Prologue , data : statement.expression.text } ) ;
if ( seenPrologueDirectives ) {
seenPrologueDirectives . add ( statement . expression . text ) ;
}
}
}
else {
// return index of the first non prologue directive
return i ;
}
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
return statements . length ;
2016-06-07 19:32:03 +02:00
}
2015-04-29 01:18:33 +02:00
2021-02-26 08:01:41 +01:00
function emitUnparsedPrologues ( prologues : readonly UnparsedPrologue [ ] , seenPrologueDirectives : Set < string > ) {
for ( const prologue of prologues ) {
if ( ! seenPrologueDirectives . has ( prologue . data ) ) {
writeLine ( ) ;
const pos = writer . getTextPos ( ) ;
emit ( prologue ) ;
if ( bundleFileInfo ) bundleFileInfo . sections . push ( { pos , end : writer.getTextPos ( ) , kind : BundleFileSectionKind.Prologue , data : prologue.data } ) ;
if ( seenPrologueDirectives ) {
seenPrologueDirectives . add ( prologue . data ) ;
}
}
}
2016-06-07 19:32:03 +02:00
}
2015-05-11 07:23:12 +02:00
2021-02-26 08:01:41 +01:00
function emitPrologueDirectivesIfNeeded ( sourceFileOrBundle : Bundle | SourceFile ) {
if ( isSourceFile ( sourceFileOrBundle ) ) {
emitPrologueDirectives ( sourceFileOrBundle . statements , sourceFileOrBundle ) ;
}
else {
const seenPrologueDirectives = new Set < string > ( ) ;
for ( const prepend of sourceFileOrBundle . prepends ) {
emitUnparsedPrologues ( ( prepend as UnparsedSource ) . prologues , seenPrologueDirectives ) ;
}
for ( const sourceFile of sourceFileOrBundle . sourceFiles ) {
emitPrologueDirectives ( sourceFile . statements , sourceFile , seenPrologueDirectives , /*recordBundleFileSection*/ true ) ;
}
setSourceFile ( undefined ) ;
}
2017-10-14 02:14:56 +02:00
}
2021-02-26 08:01:41 +01:00
function getPrologueDirectivesFromBundledSourceFiles ( bundle : Bundle ) : SourceFilePrologueInfo [ ] | undefined {
const seenPrologueDirectives = new Set < string > ( ) ;
let prologues : SourceFilePrologueInfo [ ] | undefined ;
for ( let index = 0 ; index < bundle . sourceFiles . length ; index ++ ) {
const sourceFile = bundle . sourceFiles [ index ] ;
let directives : SourceFilePrologueDirective [ ] | undefined ;
let end = 0 ;
for ( const statement of sourceFile . statements ) {
if ( ! isPrologueDirective ( statement ) ) break ;
if ( seenPrologueDirectives . has ( statement . expression . text ) ) continue ;
seenPrologueDirectives . add ( statement . expression . text ) ;
( directives || ( directives = [ ] ) ) . push ( {
pos : statement.pos ,
end : statement.end ,
expression : {
pos : statement.expression.pos ,
end : statement.expression.end ,
text : statement.expression.text
}
} ) ;
end = end < statement . end ? statement.end : end ;
2017-10-14 02:14:56 +02:00
}
2021-02-26 08:01:41 +01:00
if ( directives ) ( prologues || ( prologues = [ ] ) ) . push ( { file : index , text : sourceFile.text.substring ( 0 , end ) , directives } ) ;
2017-01-19 00:12:36 +01:00
}
2021-02-26 08:01:41 +01:00
return prologues ;
2016-06-07 19:32:03 +02:00
}
2015-04-22 07:27:33 +02:00
2021-02-26 08:01:41 +01:00
function emitShebangIfNeeded ( sourceFileOrBundle : Bundle | SourceFile | UnparsedSource ) {
if ( isSourceFile ( sourceFileOrBundle ) || isUnparsedSource ( sourceFileOrBundle ) ) {
const shebang = getShebang ( sourceFileOrBundle . text ) ;
if ( shebang ) {
writeComment ( shebang ) ;
writeLine ( ) ;
return true ;
}
}
else {
for ( const prepend of sourceFileOrBundle . prepends ) {
Debug . assertNode ( prepend , isUnparsedSource ) ;
if ( emitShebangIfNeeded ( prepend ) ) {
return true ;
}
}
for ( const sourceFile of sourceFileOrBundle . sourceFiles ) {
// Emit only the first encountered shebang
if ( emitShebangIfNeeded ( sourceFile ) ) {
return true ;
}
}
}
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
//
// Helpers
//
function emitNodeWithWriter ( node : Node | undefined , writer : typeof write ) {
if ( ! node ) return ;
const savedWrite = write ;
write = writer ;
emit ( node ) ;
write = savedWrite ;
2016-06-07 19:32:03 +02:00
}
2015-04-22 07:27:33 +02:00
2021-02-26 08:01:41 +01:00
function emitModifiers ( node : Node , modifiers : NodeArray < Modifier > | undefined ) {
if ( modifiers && modifiers . length ) {
emitList ( node , modifiers , ListFormat . Modifiers ) ;
writeSpace ( ) ;
}
2017-01-19 00:12:36 +01:00
}
2021-02-26 08:01:41 +01:00
function emitTypeAnnotation ( node : TypeNode | undefined ) {
if ( node ) {
writePunctuation ( ":" ) ;
writeSpace ( ) ;
emit ( node ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-04-11 15:14:19 +02:00
2021-04-19 18:34:46 +02:00
function emitInitializer ( node : Expression | undefined , equalCommentStartPos : number , container : Node , parenthesizerRule ? : ( node : Expression ) = > Expression ) {
2021-02-26 08:01:41 +01:00
if ( node ) {
writeSpace ( ) ;
emitTokenWithComment ( SyntaxKind . EqualsToken , equalCommentStartPos , writeOperator , container ) ;
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node , parenthesizerRule ) ;
2021-02-26 08:01:41 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-05-11 09:07:49 +02:00
2021-02-26 08:01:41 +01:00
function emitNodeWithPrefix < T extends Node > ( prefix : string , prefixWriter : ( s : string ) = > void , node : T | undefined , emit : ( node : T ) = > void ) {
if ( node ) {
prefixWriter ( prefix ) ;
emit ( node ) ;
}
2020-12-18 20:42:33 +01:00
}
2021-02-26 08:01:41 +01:00
function emitWithLeadingSpace ( node : Node | undefined ) {
if ( node ) {
writeSpace ( ) ;
emit ( node ) ;
}
2020-12-18 20:42:33 +01:00
}
2021-04-19 18:34:46 +02:00
function emitExpressionWithLeadingSpace ( node : Expression | undefined , parenthesizerRule ? : ( node : Expression ) = > Expression ) {
2021-02-26 08:01:41 +01:00
if ( node ) {
writeSpace ( ) ;
2021-04-19 18:34:46 +02:00
emitExpression ( node , parenthesizerRule ) ;
2021-02-26 08:01:41 +01:00
}
2020-12-18 20:42:33 +01:00
}
2021-02-26 08:01:41 +01:00
function emitWithTrailingSpace ( node : Node | undefined ) {
if ( node ) {
emit ( node ) ;
writeSpace ( ) ;
2016-06-07 19:32:03 +02:00
}
}
2015-04-22 07:27:33 +02:00
2021-02-26 08:01:41 +01:00
function emitEmbeddedStatement ( parent : Node , node : Statement ) {
if ( isBlock ( node ) || getEmitFlags ( parent ) & EmitFlags . SingleLine ) {
writeSpace ( ) ;
emit ( node ) ;
2016-06-07 19:32:03 +02:00
}
else {
2021-02-26 08:01:41 +01:00
writeLine ( ) ;
increaseIndent ( ) ;
if ( isEmptyStatement ( node ) ) {
2021-04-19 18:34:46 +02:00
pipelineEmit ( EmitHint . EmbeddedStatement , node ) ;
2021-02-26 08:01:41 +01:00
}
else {
emit ( node ) ;
}
decreaseIndent ( ) ;
2016-06-07 19:32:03 +02:00
}
}
2015-05-11 09:07:49 +02:00
2021-02-26 08:01:41 +01:00
function emitDecorators ( parentNode : Node , decorators : NodeArray < Decorator > | undefined ) {
emitList ( parentNode , decorators , ListFormat . Decorators ) ;
}
2015-05-11 09:07:49 +02:00
2021-02-26 08:01:41 +01:00
function emitTypeArguments ( parentNode : Node , typeArguments : NodeArray < TypeNode > | undefined ) {
2021-04-19 18:34:46 +02:00
emitList ( parentNode , typeArguments , ListFormat . TypeArguments , parenthesizer . parenthesizeMemberOfElementType ) ;
2021-02-26 08:01:41 +01:00
}
2015-04-11 15:33:09 +02:00
2021-02-26 08:01:41 +01:00
function emitTypeParameters ( parentNode : SignatureDeclaration | InterfaceDeclaration | TypeAliasDeclaration | ClassDeclaration | ClassExpression , typeParameters : NodeArray < TypeParameterDeclaration > | undefined ) {
if ( isFunctionLike ( parentNode ) && parentNode . typeArguments ) { // Quick info uses type arguments in place of type parameters on instantiated signatures
return emitTypeArguments ( parentNode , parentNode . typeArguments ) ;
}
emitList ( parentNode , typeParameters , ListFormat . TypeParameters ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-22 07:27:33 +02:00
2021-02-26 08:01:41 +01:00
function emitParameters ( parentNode : Node , parameters : NodeArray < ParameterDeclaration > ) {
emitList ( parentNode , parameters , ListFormat . Parameters ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function canEmitSimpleArrowHead ( parentNode : FunctionTypeNode | ArrowFunction , parameters : NodeArray < ParameterDeclaration > ) {
const parameter = singleOrUndefined ( parameters ) ;
return parameter
&& parameter . pos === parentNode . pos // may not have parsed tokens between parent and parameter
&& isArrowFunction ( parentNode ) // only arrow functions may have simple arrow head
&& ! parentNode . type // arrow function may not have return type annotation
&& ! some ( parentNode . decorators ) // parent may not have decorators
&& ! some ( parentNode . modifiers ) // parent may not have modifiers
&& ! some ( parentNode . typeParameters ) // parent may not have type parameters
&& ! some ( parameter . decorators ) // parameter may not have decorators
&& ! some ( parameter . modifiers ) // parameter may not have modifiers
&& ! parameter . dotDotDotToken // parameter may not be rest
&& ! parameter . questionToken // parameter may not be optional
&& ! parameter . type // parameter may not have a type annotation
&& ! parameter . initializer // parameter may not have an initializer
&& isIdentifier ( parameter . name ) ; // parameter name must be identifier
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function emitParametersForArrow ( parentNode : FunctionTypeNode | ArrowFunction , parameters : NodeArray < ParameterDeclaration > ) {
if ( canEmitSimpleArrowHead ( parentNode , parameters ) ) {
emitList ( parentNode , parameters , ListFormat . Parameters & ~ ListFormat . Parenthesis ) ;
2016-06-07 19:32:03 +02:00
}
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
else {
2021-02-26 08:01:41 +01:00
emitParameters ( parentNode , parameters ) ;
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-07-27 13:52:57 +02:00
2021-02-26 08:01:41 +01:00
function emitParametersForIndexSignature ( parentNode : Node , parameters : NodeArray < ParameterDeclaration > ) {
emitList ( parentNode , parameters , ListFormat . IndexSignatureParameters ) ;
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function writeDelimiter ( format : ListFormat ) {
switch ( format & ListFormat . DelimitersMask ) {
case ListFormat . None :
break ;
case ListFormat . CommaDelimited :
writePunctuation ( "," ) ;
break ;
case ListFormat . BarDelimited :
writeSpace ( ) ;
writePunctuation ( "|" ) ;
break ;
case ListFormat . AsteriskDelimited :
writeSpace ( ) ;
writePunctuation ( "*" ) ;
writeSpace ( ) ;
break ;
case ListFormat . AmpersandDelimited :
writeSpace ( ) ;
writePunctuation ( "&" ) ;
break ;
2017-07-30 10:30:59 +02:00
}
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-04-19 18:34:46 +02:00
function emitList ( parentNode : Node | undefined , children : NodeArray < Node > | undefined , format : ListFormat , parenthesizerRule ? : ( node : Node ) = > Node , start? : number , count? : number ) {
emitNodeList ( emit , parentNode , children , format , parenthesizerRule , start , count ) ;
}
function emitExpressionList ( parentNode : Node | undefined , children : NodeArray < Node > | undefined , format : ListFormat , parenthesizerRule ? : ( node : Expression ) = > Expression , start? : number , count? : number ) {
emitNodeList ( emitExpression , parentNode , children , format , parenthesizerRule , start , count ) ;
}
function emitNodeList ( emit : ( node : Node , parenthesizerRule ? : ( ( node : Node ) = > Node ) | undefined ) = > void , parentNode : Node | undefined , children : NodeArray < Node > | undefined , format : ListFormat , parenthesizerRule : ( ( node : Node ) = > Node ) | undefined , start = 0 , count = children ? children . length - start : 0 ) {
2021-02-26 08:01:41 +01:00
const isUndefined = children === undefined ;
if ( isUndefined && format & ListFormat . OptionalIfUndefined ) {
return ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
const isEmpty = children === undefined || start >= children . length || count === 0 ;
if ( isEmpty && format & ListFormat . OptionalIfEmpty ) {
if ( onBeforeEmitNodeArray ) {
onBeforeEmitNodeArray ( children ) ;
}
if ( onAfterEmitNodeArray ) {
onAfterEmitNodeArray ( children ) ;
}
return ;
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
if ( format & ListFormat . BracketsMask ) {
writePunctuation ( getOpeningBracket ( format ) ) ;
if ( isEmpty && children ) {
emitTrailingCommentsOfPosition ( children . pos , /*prefixSpace*/ true ) ; // Emit comments within empty bracketed lists
}
2015-04-10 21:10:38 +02:00
}
2021-02-26 08:01:41 +01:00
if ( onBeforeEmitNodeArray ) {
onBeforeEmitNodeArray ( children ) ;
2016-11-07 18:04:00 +01:00
}
2021-02-26 08:01:41 +01:00
if ( isEmpty ) {
// Write a line terminator if the parent node was multi-line
if ( format & ListFormat . MultiLine && ! ( preserveSourceNewlines && ( ! parentNode || rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ) ) ) {
writeLine ( ) ;
}
else if ( format & ListFormat . SpaceBetweenBraces && ! ( format & ListFormat . NoSpaceIfEmpty ) ) {
writeSpace ( ) ;
}
}
else {
Debug . type < NodeArray < Node > > ( children ) ;
// Write the opening line terminator or leading whitespace.
const mayEmitInterveningComments = ( format & ListFormat . NoInterveningComments ) === 0 ;
let shouldEmitInterveningComments = mayEmitInterveningComments ;
const leadingLineTerminatorCount = getLeadingLineTerminatorCount ( parentNode , children , format ) ; // TODO: GH#18217
if ( leadingLineTerminatorCount ) {
writeLine ( leadingLineTerminatorCount ) ;
shouldEmitInterveningComments = false ;
}
else if ( format & ListFormat . SpaceBetweenBraces ) {
writeSpace ( ) ;
}
// Increase the indent, if requested.
if ( format & ListFormat . Indented ) {
increaseIndent ( ) ;
}
// Emit each child.
let previousSibling : Node | undefined ;
let previousSourceFileTextKind : ReturnType < typeof recordBundleFileInternalSectionStart > ;
let shouldDecreaseIndentAfterEmit = false ;
for ( let i = 0 ; i < count ; i ++ ) {
const child = children [ start + i ] ;
// Write the delimiter if this is not the first node.
if ( format & ListFormat . AsteriskDelimited ) {
// always write JSDoc in the format "\n *"
writeLine ( ) ;
writeDelimiter ( format ) ;
}
else if ( previousSibling ) {
// i.e
// function commentedParameters(
// /* Parameter a */
// a
// /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline
// ,
if ( format & ListFormat . DelimitersMask && previousSibling . end !== ( parentNode ? parentNode . end : - 1 ) ) {
emitLeadingCommentsOfPosition ( previousSibling . end ) ;
}
writeDelimiter ( format ) ;
recordBundleFileInternalSectionEnd ( previousSourceFileTextKind ) ;
// Write either a line terminator or whitespace to separate the elements.
const separatingLineTerminatorCount = getSeparatingLineTerminatorCount ( previousSibling , child , format ) ;
if ( separatingLineTerminatorCount > 0 ) {
// If a synthesized node in a single-line list starts on a new
// line, we should increase the indent.
if ( ( format & ( ListFormat . LinesMask | ListFormat . Indented ) ) === ListFormat . SingleLine ) {
increaseIndent ( ) ;
shouldDecreaseIndentAfterEmit = true ;
}
writeLine ( separatingLineTerminatorCount ) ;
shouldEmitInterveningComments = false ;
}
else if ( previousSibling && format & ListFormat . SpaceBetweenSiblings ) {
writeSpace ( ) ;
}
}
// Emit this child.
previousSourceFileTextKind = recordBundleFileInternalSectionStart ( child ) ;
if ( shouldEmitInterveningComments ) {
if ( emitTrailingCommentsOfPosition ) {
const commentRange = getCommentRange ( child ) ;
emitTrailingCommentsOfPosition ( commentRange . pos ) ;
}
}
else {
shouldEmitInterveningComments = mayEmitInterveningComments ;
}
nextListElementPos = child . pos ;
2021-04-19 18:34:46 +02:00
if ( emit . length === 1 ) {
emit ( child ) ;
}
else {
emit ( child , parenthesizerRule ) ;
}
2021-02-26 08:01:41 +01:00
if ( shouldDecreaseIndentAfterEmit ) {
decreaseIndent ( ) ;
shouldDecreaseIndentAfterEmit = false ;
}
previousSibling = child ;
}
// Write a trailing comma, if requested.
const emitFlags = previousSibling ? getEmitFlags ( previousSibling ) : 0 ;
const skipTrailingComments = commentsDisabled || ! ! ( emitFlags & EmitFlags . NoTrailingComments ) ;
const hasTrailingComma = children ? . hasTrailingComma && ( format & ListFormat . AllowTrailingComma ) && ( format & ListFormat . CommaDelimited ) ;
if ( hasTrailingComma ) {
if ( previousSibling && ! skipTrailingComments ) {
emitTokenWithComment ( SyntaxKind . CommaToken , previousSibling . end , writePunctuation , previousSibling ) ;
}
else {
writePunctuation ( "," ) ;
}
}
// Emit any trailing comment of the last element in the list
// i.e
// var array = [...
// 2
// /* end of element 2 */
// ];
if ( previousSibling && ( parentNode ? parentNode . end : - 1 ) !== previousSibling . end && ( format & ListFormat . DelimitersMask ) && ! skipTrailingComments ) {
emitLeadingCommentsOfPosition ( hasTrailingComma && children ? . end ? children.end : previousSibling.end ) ;
}
2015-10-01 00:45:23 +02:00
2021-02-26 08:01:41 +01:00
// Decrease the indent, if requested.
if ( format & ListFormat . Indented ) {
decreaseIndent ( ) ;
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
recordBundleFileInternalSectionEnd ( previousSourceFileTextKind ) ;
// Write the closing line terminator or closing whitespace.
const closingLineTerminatorCount = getClosingLineTerminatorCount ( parentNode , children , format ) ;
if ( closingLineTerminatorCount ) {
writeLine ( closingLineTerminatorCount ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
else if ( format & ( ListFormat . SpaceAfterList | ListFormat . SpaceBetweenBraces ) ) {
2018-10-25 01:14:52 +02:00
writeSpace ( ) ;
}
2021-02-26 08:01:41 +01:00
}
if ( onAfterEmitNodeArray ) {
onAfterEmitNodeArray ( children ) ;
}
if ( format & ListFormat . BracketsMask ) {
if ( isEmpty && children ) {
emitLeadingCommentsOfPosition ( children . end ) ; // Emit leading comments within empty lists
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
writePunctuation ( getClosingBracket ( format ) ) ;
2018-10-25 01:14:52 +02:00
}
}
2021-02-26 08:01:41 +01:00
// Writers
function writeLiteral ( s : string ) {
writer . writeLiteral ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeStringLiteral ( s : string ) {
writer . writeStringLiteral ( s ) ;
2020-09-09 19:45:09 +02:00
}
2021-02-26 08:01:41 +01:00
function writeBase ( s : string ) {
writer . write ( s ) ;
2020-09-09 19:45:09 +02:00
}
2021-02-26 08:01:41 +01:00
function writeSymbol ( s : string , sym : Symbol ) {
writer . writeSymbol ( s , sym ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writePunctuation ( s : string ) {
writer . writePunctuation ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeTrailingSemicolon() {
writer . writeTrailingSemicolon ( ";" ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeKeyword ( s : string ) {
writer . writeKeyword ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeOperator ( s : string ) {
writer . writeOperator ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeParameter ( s : string ) {
writer . writeParameter ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeComment ( s : string ) {
writer . writeComment ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeSpace() {
writer . writeSpace ( " " ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeProperty ( s : string ) {
writer . writeProperty ( s ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function writeLine ( count = 1 ) {
for ( let i = 0 ; i < count ; i ++ ) {
writer . writeLine ( i > 0 ) ;
2018-10-25 01:14:52 +02:00
}
}
2021-02-26 08:01:41 +01:00
function increaseIndent() {
writer . increaseIndent ( ) ;
2018-10-25 01:14:52 +02:00
}
2021-02-26 08:01:41 +01:00
function decreaseIndent() {
writer . decreaseIndent ( ) ;
}
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
function writeToken ( token : SyntaxKind , pos : number , writer : ( s : string ) = > void , contextNode? : Node ) {
return ! sourceMapsDisabled
? emitTokenWithSourceMap ( contextNode , token , writer , pos , writeTokenText )
: writeTokenText ( token , writer , pos ) ;
2016-06-07 19:32:03 +02:00
}
2015-10-01 00:45:23 +02:00
2021-02-26 08:01:41 +01:00
function writeTokenNode ( node : Node , writer : ( s : string ) = > void ) {
if ( onBeforeEmitToken ) {
onBeforeEmitToken ( node ) ;
}
writer ( tokenToString ( node . kind ) ! ) ;
if ( onAfterEmitToken ) {
onAfterEmitToken ( node ) ;
2019-02-20 19:54:31 +01:00
}
2018-03-16 06:23:10 +01:00
}
2021-02-26 08:01:41 +01:00
function writeTokenText ( token : SyntaxKind , writer : ( s : string ) = > void ) : void ;
function writeTokenText ( token : SyntaxKind , writer : ( s : string ) = > void , pos : number ) : number ;
function writeTokenText ( token : SyntaxKind , writer : ( s : string ) = > void , pos? : number ) : number {
const tokenString = tokenToString ( token ) ! ;
writer ( tokenString ) ;
return pos ! < 0 ? pos ! : pos ! + tokenString . length ;
2018-03-16 06:23:10 +01:00
}
2021-02-26 08:01:41 +01:00
function writeLineOrSpace ( parentNode : Node , prevChildNode : Node , nextChildNode : Node ) {
if ( getEmitFlags ( parentNode ) & EmitFlags . SingleLine ) {
writeSpace ( ) ;
}
else if ( preserveSourceNewlines ) {
const lines = getLinesBetweenNodes ( parentNode , prevChildNode , nextChildNode ) ;
if ( lines ) {
writeLine ( lines ) ;
}
else {
writeSpace ( ) ;
}
2018-03-30 00:38:29 +02:00
}
2021-02-26 08:01:41 +01:00
else {
2018-03-29 22:43:31 +02:00
writeLine ( ) ;
}
2021-02-26 08:01:41 +01:00
}
function writeLines ( text : string ) : void {
const lines = text . split ( /\r\n?|\n/g ) ;
const indentation = guessIndentation ( lines ) ;
for ( const lineText of lines ) {
const line = indentation ? lineText . slice ( indentation ) : lineText ;
if ( line . length ) {
2018-03-29 22:43:31 +02:00
writeLine ( ) ;
2021-02-26 08:01:41 +01:00
write ( line ) ;
2018-03-29 22:43:31 +02:00
}
}
2018-03-16 06:23:10 +01:00
}
2021-02-26 08:01:41 +01:00
function writeLinesAndIndent ( lineCount : number , writeSpaceIfNotIndenting : boolean ) {
if ( lineCount ) {
increaseIndent ( ) ;
writeLine ( lineCount ) ;
}
else if ( writeSpaceIfNotIndenting ) {
writeSpace ( ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-10-01 00:45:23 +02:00
2021-02-26 08:01:41 +01:00
// Helper function to decrease the indent if we previously indented. Allows multiple
// previous indent values to be considered at a time. This also allows caller to just
// call this once, passing in all their appropriate indent values, instead of needing
// to call this helper function multiple times.
function decreaseIndentIf ( value1 : boolean | number | undefined , value2? : boolean | number ) {
if ( value1 ) {
decreaseIndent ( ) ;
}
if ( value2 ) {
decreaseIndent ( ) ;
}
2016-06-07 19:32:03 +02:00
}
2015-04-10 21:10:38 +02:00
2021-02-26 08:01:41 +01:00
function getLeadingLineTerminatorCount ( parentNode : Node | undefined , children : readonly Node [ ] , format : ListFormat ) : number {
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
if ( format & ListFormat . PreferNewLine ) {
return 1 ;
}
2017-05-12 08:51:20 +02:00
2021-02-26 08:01:41 +01:00
const firstChild = children [ 0 ] ;
if ( firstChild === undefined ) {
return ! parentNode || rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
}
if ( firstChild . pos === nextListElementPos ) {
// If this child starts at the beginning of a list item in a parent list, its leading
// line terminators have already been written as the separating line terminators of the
// parent list. Example:
//
// class Foo {
// constructor() {}
// public foo() {}
// }
//
// The outer list is the list of class members, with one line terminator between the
// constructor and the method. The constructor is written, the separating line terminator
// is written, and then we start emitting the method. Its modifiers ([public]) constitute an inner
// list, so we look for its leading line terminators. If we didn't know that we had already
// written a newline as part of the parent list, it would appear that we need to write a
// leading newline to start the modifiers.
return 0 ;
}
if ( firstChild . kind === SyntaxKind . JsxText ) {
// JsxText will be written with its leading whitespace, so don't add more manually.
return 0 ;
}
if ( parentNode &&
! positionIsSynthesized ( parentNode . pos ) &&
! nodeIsSynthesized ( firstChild ) &&
( ! firstChild . parent || getOriginalNode ( firstChild . parent ) === getOriginalNode ( parentNode ) )
) {
if ( preserveSourceNewlines ) {
return getEffectiveLines (
includeComments = > getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter (
firstChild . pos ,
parentNode . pos ,
currentSourceFile ! ,
includeComments ) ) ;
2015-02-10 23:59:20 +01:00
}
2021-02-26 08:01:41 +01:00
return rangeStartPositionsAreOnSameLine ( parentNode , firstChild , currentSourceFile ! ) ? 0 : 1 ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
if ( synthesizedNodeStartsOnNewLine ( firstChild , format ) ) {
return 1 ;
2016-06-07 19:32:03 +02:00
}
}
2021-02-26 08:01:41 +01:00
return format & ListFormat . MultiLine ? 1 : 0 ;
2016-06-07 19:32:03 +02:00
}
2015-08-07 01:38:53 +02:00
2021-02-26 08:01:41 +01:00
function getSeparatingLineTerminatorCount ( previousNode : Node | undefined , nextNode : Node , format : ListFormat ) : number {
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
if ( previousNode === undefined || nextNode === undefined ) {
return 0 ;
}
if ( nextNode . kind === SyntaxKind . JsxText ) {
// JsxText will be written with its leading whitespace, so don't add more manually.
return 0 ;
}
2021-06-04 16:46:23 +02:00
else if ( ! nodeIsSynthesized ( previousNode ) && ! nodeIsSynthesized ( nextNode ) ) {
if ( preserveSourceNewlines && siblingNodePositionsAreComparable ( previousNode , nextNode ) ) {
return getEffectiveLines (
includeComments = > getLinesBetweenRangeEndAndRangeStart (
previousNode ,
nextNode ,
currentSourceFile ! ,
includeComments ) ) ;
}
// If `preserveSourceNewlines` is `false` we do not intend to preserve the effective lines between the
// previous and next node. Instead we naively check whether nodes are on separate lines within the
// same node parent. If so, we intend to preserve a single line terminator. This is less precise and
// expensive than checking with `preserveSourceNewlines` as above, but the goal is not to preserve the
// effective source lines between two sibling nodes.
else if ( ! preserveSourceNewlines && originalNodesHaveSameParent ( previousNode , nextNode ) ) {
return rangeEndIsOnSameLineAsRangeStart ( previousNode , nextNode , currentSourceFile ! ) ? 0 : 1 ;
}
// If the two nodes are not comparable, add a line terminator based on the format that can indicate
// whether new lines are preferred or not.
return format & ListFormat . PreferNewLine ? 1 : 0 ;
2021-02-26 08:01:41 +01:00
}
else if ( synthesizedNodeStartsOnNewLine ( previousNode , format ) || synthesizedNodeStartsOnNewLine ( nextNode , format ) ) {
return 1 ;
2019-01-17 21:11:51 +01:00
}
}
2021-02-26 08:01:41 +01:00
else if ( getStartsOnNewLine ( nextNode ) ) {
return 1 ;
}
return format & ListFormat . MultiLine ? 1 : 0 ;
2019-01-17 21:11:51 +01:00
}
2021-02-26 08:01:41 +01:00
function getClosingLineTerminatorCount ( parentNode : Node | undefined , children : readonly Node [ ] , format : ListFormat ) : number {
if ( format & ListFormat . PreserveLines || preserveSourceNewlines ) {
if ( format & ListFormat . PreferNewLine ) {
return 1 ;
2019-01-17 21:11:51 +01:00
}
2021-02-26 08:01:41 +01:00
const lastChild = lastOrUndefined ( children ) ;
if ( lastChild === undefined ) {
return ! parentNode || rangeIsOnSingleLine ( parentNode , currentSourceFile ! ) ? 0 : 1 ;
}
if ( parentNode && ! positionIsSynthesized ( parentNode . pos ) && ! nodeIsSynthesized ( lastChild ) && ( ! lastChild . parent || lastChild . parent === parentNode ) ) {
if ( preserveSourceNewlines ) {
const end = isNodeArray ( children ) && ! positionIsSynthesized ( children . end ) ? children.end : lastChild.end ;
return getEffectiveLines (
includeComments = > getLinesBetweenPositionAndNextNonWhitespaceCharacter (
end ,
parentNode . end ,
currentSourceFile ! ,
includeComments ) ) ;
}
return rangeEndPositionsAreOnSameLine ( parentNode , lastChild , currentSourceFile ! ) ? 0 : 1 ;
}
if ( synthesizedNodeStartsOnNewLine ( lastChild , format ) ) {
return 1 ;
2017-02-24 20:37:34 +01:00
}
}
2021-02-26 08:01:41 +01:00
if ( format & ListFormat . MultiLine && ! ( format & ListFormat . NoTrailingNewLine ) ) {
return 1 ;
}
return 0 ;
2017-02-24 20:37:34 +01:00
}
2015-04-20 22:40:13 +02:00
2021-02-26 08:01:41 +01:00
function getEffectiveLines ( getLineDifference : ( includeComments : boolean ) = > number ) {
// If 'preserveSourceNewlines' is disabled, we should never call this function
// because it could be more expensive than alternative approximations.
Debug . assert ( ! ! preserveSourceNewlines ) ;
// We start by measuring the line difference from a position to its adjacent comments,
// so that this is counted as a one-line difference, not two:
//
// node1;
// // NODE2 COMMENT
// node2;
const lines = getLineDifference ( /*includeComments*/ true ) ;
if ( lines === 0 ) {
// However, if the line difference considering comments was 0, we might have this:
//
// node1; // NODE2 COMMENT
// node2;
//
// in which case we should be ignoring node2's comment, so this too is counted as
// a one-line difference, not zero.
return getLineDifference ( /*includeComments*/ false ) ;
}
return lines ;
}
function writeLineSeparatorsAndIndentBefore ( node : Node , parent : Node ) : boolean {
const leadingNewlines = preserveSourceNewlines && getLeadingLineTerminatorCount ( parent , [ node ] , ListFormat . None ) ;
if ( leadingNewlines ) {
writeLinesAndIndent ( leadingNewlines , /*writeLinesIfNotIndenting*/ false ) ;
2019-02-04 23:49:24 +01:00
}
2021-02-26 08:01:41 +01:00
return ! ! leadingNewlines ;
2019-02-04 23:49:24 +01:00
}
2021-02-26 08:01:41 +01:00
function writeLineSeparatorsAfter ( node : Node , parent : Node ) {
const trailingNewlines = preserveSourceNewlines && getClosingLineTerminatorCount ( parent , [ node ] , ListFormat . None ) ;
if ( trailingNewlines ) {
writeLine ( trailingNewlines ) ;
2017-02-24 00:27:22 +01:00
}
2021-02-26 08:01:41 +01:00
}
function synthesizedNodeStartsOnNewLine ( node : Node , format : ListFormat ) {
if ( nodeIsSynthesized ( node ) ) {
const startsOnNewLine = getStartsOnNewLine ( node ) ;
if ( startsOnNewLine === undefined ) {
return ( format & ListFormat . PreferNewLine ) !== 0 ;
2017-02-24 00:27:22 +01:00
}
2021-02-26 08:01:41 +01:00
return startsOnNewLine ;
2017-02-24 00:27:22 +01:00
}
2021-02-26 08:01:41 +01:00
return ( format & ListFormat . PreferNewLine ) !== 0 ;
2016-06-07 19:32:03 +02:00
}
2017-02-24 20:37:34 +01:00
2021-02-26 08:01:41 +01:00
function getLinesBetweenNodes ( parent : Node , node1 : Node , node2 : Node ) : number {
if ( getEmitFlags ( parent ) & EmitFlags . NoIndentation ) {
return 0 ;
}
2017-02-24 20:37:34 +01:00
2021-02-26 08:01:41 +01:00
parent = skipSynthesizedParentheses ( parent ) ;
node1 = skipSynthesizedParentheses ( node1 ) ;
node2 = skipSynthesizedParentheses ( node2 ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
2021-02-26 08:01:41 +01:00
// Always use a newline for synthesized code if the synthesizer desires it.
if ( getStartsOnNewLine ( node2 ) ) {
return 1 ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
if ( ! nodeIsSynthesized ( parent ) && ! nodeIsSynthesized ( node1 ) && ! nodeIsSynthesized ( node2 ) ) {
if ( preserveSourceNewlines ) {
return getEffectiveLines (
includeComments = > getLinesBetweenRangeEndAndRangeStart (
node1 ,
node2 ,
currentSourceFile ! ,
includeComments ) ) ;
}
return rangeEndIsOnSameLineAsRangeStart ( node1 , node2 , currentSourceFile ! ) ? 0 : 1 ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
return 0 ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function isEmptyBlock ( block : BlockLike ) {
return block . statements . length === 0
&& rangeEndIsOnSameLineAsRangeStart ( block , block , currentSourceFile ! ) ;
}
function skipSynthesizedParentheses ( node : Node ) {
while ( node . kind === SyntaxKind . ParenthesizedExpression && nodeIsSynthesized ( node ) ) {
2021-05-18 15:20:57 +02:00
node = ( node as ParenthesizedExpression ) . expression ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
return node ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function getTextOfNode ( node : Node , includeTrivia? : boolean ) : string {
if ( isGeneratedIdentifier ( node ) ) {
return generateName ( node ) ;
}
else if ( ( isIdentifier ( node ) || isPrivateIdentifier ( node ) ) && ( nodeIsSynthesized ( node ) || ! node . parent || ! currentSourceFile || ( node . parent && currentSourceFile && getSourceFileOfNode ( node ) !== getOriginalNode ( currentSourceFile ) ) ) ) {
return idText ( node ) ;
}
2021-05-18 15:20:57 +02:00
else if ( node . kind === SyntaxKind . StringLiteral && ( node as StringLiteral ) . textSourceNode ) {
return getTextOfNode ( ( node as StringLiteral ) . textSourceNode ! , includeTrivia ) ;
2021-02-26 08:01:41 +01:00
}
else if ( isLiteralExpression ( node ) && ( nodeIsSynthesized ( node ) || ! node . parent ) ) {
return node . text ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
return getSourceTextOfNodeFromSourceFile ( currentSourceFile ! , node , includeTrivia ) ;
2016-06-07 19:32:03 +02:00
}
2015-09-26 00:22:01 +02:00
2021-02-26 08:01:41 +01:00
function getLiteralTextOfNode ( node : LiteralLikeNode , neverAsciiEscape : boolean | undefined , jsxAttributeEscape : boolean ) : string {
2021-05-18 15:20:57 +02:00
if ( node . kind === SyntaxKind . StringLiteral && ( node as StringLiteral ) . textSourceNode ) {
const textSourceNode = ( node as StringLiteral ) . textSourceNode ! ;
2021-02-26 08:01:41 +01:00
if ( isIdentifier ( textSourceNode ) || isNumericLiteral ( textSourceNode ) ) {
const text = isNumericLiteral ( textSourceNode ) ? textSourceNode.text : getTextOfNode ( textSourceNode ) ;
return jsxAttributeEscape ? ` " ${ escapeJsxAttributeString ( text ) } " ` :
neverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? ` " ${ escapeString ( text ) } " ` :
` " ${ escapeNonAsciiString ( text ) } " ` ;
}
else {
return getLiteralTextOfNode ( textSourceNode , neverAsciiEscape , jsxAttributeEscape ) ;
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
const flags = ( neverAsciiEscape ? GetLiteralTextFlags.NeverAsciiEscape : 0 )
| ( jsxAttributeEscape ? GetLiteralTextFlags.JsxAttributeEscape : 0 )
| ( printerOptions . terminateUnterminatedLiterals ? GetLiteralTextFlags.TerminateUnterminatedLiterals : 0 )
| ( printerOptions . target && printerOptions . target === ScriptTarget . ESNext ? GetLiteralTextFlags.AllowNumericSeparator : 0 ) ;
return getLiteralText ( node , currentSourceFile ! , flags ) ;
2016-06-07 19:32:03 +02:00
}
2015-09-26 00:22:01 +02:00
2021-02-26 08:01:41 +01:00
/ * *
* Push a new name generation scope .
* /
function pushNameGenerationScope ( node : Node | undefined ) {
if ( node && getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
return ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
tempFlagsStack . push ( tempFlags ) ;
tempFlags = 0 ;
reservedNamesStack . push ( reservedNames ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Pop the current name generation scope .
* /
function popNameGenerationScope ( node : Node | undefined ) {
if ( node && getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
return ;
2015-09-26 00:22:01 +02:00
}
2021-02-26 08:01:41 +01:00
tempFlags = tempFlagsStack . pop ( ) ! ;
reservedNames = reservedNamesStack . pop ( ) ! ;
2016-06-07 19:32:03 +02:00
}
2015-09-26 00:22:01 +02:00
2021-02-26 08:01:41 +01:00
function reserveNameInNestedScopes ( name : string ) {
if ( ! reservedNames || reservedNames === lastOrUndefined ( reservedNamesStack ) ) {
reservedNames = new Set ( ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
reservedNames . add ( name ) ;
}
function generateNames ( node : Node | undefined ) {
if ( ! node ) return ;
switch ( node . kind ) {
case SyntaxKind . Block :
2021-05-18 15:20:57 +02:00
forEach ( ( node as Block ) . statements , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . LabeledStatement :
case SyntaxKind . WithStatement :
case SyntaxKind . DoStatement :
case SyntaxKind . WhileStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as LabeledStatement | WithStatement | DoStatement | WhileStatement ) . statement ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . IfStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as IfStatement ) . thenStatement ) ;
generateNames ( ( node as IfStatement ) . elseStatement ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . ForStatement :
case SyntaxKind . ForOfStatement :
case SyntaxKind . ForInStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as ForStatement | ForInOrOfStatement ) . initializer ) ;
generateNames ( ( node as ForStatement | ForInOrOfStatement ) . statement ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . SwitchStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as SwitchStatement ) . caseBlock ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . CaseBlock :
2021-05-18 15:20:57 +02:00
forEach ( ( node as CaseBlock ) . clauses , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . CaseClause :
case SyntaxKind . DefaultClause :
2021-05-18 15:20:57 +02:00
forEach ( ( node as CaseOrDefaultClause ) . statements , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . TryStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as TryStatement ) . tryBlock ) ;
generateNames ( ( node as TryStatement ) . catchClause ) ;
generateNames ( ( node as TryStatement ) . finallyBlock ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . CatchClause :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as CatchClause ) . variableDeclaration ) ;
generateNames ( ( node as CatchClause ) . block ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . VariableStatement :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as VariableStatement ) . declarationList ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . VariableDeclarationList :
2021-05-18 15:20:57 +02:00
forEach ( ( node as VariableDeclarationList ) . declarations , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . VariableDeclaration :
case SyntaxKind . Parameter :
case SyntaxKind . BindingElement :
case SyntaxKind . ClassDeclaration :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as NamedDeclaration ) . name ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . FunctionDeclaration :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as FunctionDeclaration ) . name ) ;
2021-02-26 08:01:41 +01:00
if ( getEmitFlags ( node ) & EmitFlags . ReuseTempVariableScope ) {
2021-05-18 15:20:57 +02:00
forEach ( ( node as FunctionDeclaration ) . parameters , generateNames ) ;
generateNames ( ( node as FunctionDeclaration ) . body ) ;
2021-02-26 08:01:41 +01:00
}
break ;
case SyntaxKind . ObjectBindingPattern :
case SyntaxKind . ArrayBindingPattern :
2021-05-18 15:20:57 +02:00
forEach ( ( node as BindingPattern ) . elements , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . ImportDeclaration :
2021-05-18 15:20:57 +02:00
generateNames ( ( node as ImportDeclaration ) . importClause ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . ImportClause :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as ImportClause ) . name ) ;
generateNames ( ( node as ImportClause ) . namedBindings ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . NamespaceImport :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as NamespaceImport ) . name ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . NamespaceExport :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as NamespaceExport ) . name ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . NamedImports :
2021-05-18 15:20:57 +02:00
forEach ( ( node as NamedImports ) . elements , generateNames ) ;
2021-02-26 08:01:41 +01:00
break ;
case SyntaxKind . ImportSpecifier :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as ImportSpecifier ) . propertyName || ( node as ImportSpecifier ) . name ) ;
2021-02-26 08:01:41 +01:00
break ;
2014-07-12 00:13:01 +02:00
}
2016-06-07 19:32:03 +02:00
}
2014-07-12 00:13:01 +02:00
2021-02-26 08:01:41 +01:00
function generateMemberNames ( node : Node | undefined ) {
if ( ! node ) return ;
switch ( node . kind ) {
case SyntaxKind . PropertyAssignment :
case SyntaxKind . ShorthandPropertyAssignment :
case SyntaxKind . PropertyDeclaration :
case SyntaxKind . MethodDeclaration :
case SyntaxKind . GetAccessor :
case SyntaxKind . SetAccessor :
2021-05-18 15:20:57 +02:00
generateNameIfNeeded ( ( node as NamedDeclaration ) . name ) ;
2021-02-26 08:01:41 +01:00
break ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-04-03 08:05:58 +02:00
2021-02-26 08:01:41 +01:00
function generateNameIfNeeded ( name : DeclarationName | undefined ) {
if ( name ) {
if ( isGeneratedIdentifier ( name ) ) {
generateName ( name ) ;
}
else if ( isBindingPattern ( name ) ) {
generateNames ( name ) ;
}
}
2017-06-08 00:13:24 +02:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generate the text for a generated identifier .
* /
function generateName ( name : GeneratedIdentifier ) {
if ( ( name . autoGenerateFlags & GeneratedIdentifierFlags . KindMask ) === GeneratedIdentifierFlags . Node ) {
// Node names generate unique names based on their original node
// and are cached based on that node's id.
return generateNameCached ( getNodeForGeneratedName ( name ) , name . autoGenerateFlags ) ;
2015-03-17 03:25:02 +01:00
}
2016-06-07 19:32:03 +02:00
else {
2021-02-26 08:01:41 +01:00
// Auto, Loop, and Unique names are cached based on their unique
// autoGenerateId.
const autoGenerateId = name . autoGenerateId ! ;
return autoGeneratedIdToGeneratedName [ autoGenerateId ] || ( autoGeneratedIdToGeneratedName [ autoGenerateId ] = makeName ( name ) ) ;
2014-10-11 01:44:14 +02:00
}
2016-06-07 19:32:03 +02:00
}
2014-08-04 21:06:07 +02:00
2021-02-26 08:01:41 +01:00
function generateNameCached ( node : Node , flags? : GeneratedIdentifierFlags ) {
const nodeId = getNodeId ( node ) ;
return nodeIdToGeneratedName [ nodeId ] || ( nodeIdToGeneratedName [ nodeId ] = generateNameForNode ( node , flags ) ) ;
2016-06-07 19:32:03 +02:00
}
2015-08-20 21:20:28 +02:00
2021-02-26 08:01:41 +01:00
/ * *
* Returns a value indicating whether a name is unique globally , within the current file ,
* or within the NameGenerator .
* /
function isUniqueName ( name : string ) : boolean {
return isFileLevelUniqueName ( name )
&& ! generatedNames . has ( name )
&& ! ( reservedNames && reservedNames . has ( name ) ) ;
2016-06-07 19:32:03 +02:00
}
2015-06-18 23:01:49 +02:00
2021-02-26 08:01:41 +01:00
/ * *
* Returns a value indicating whether a name is unique globally or within the current file .
* /
function isFileLevelUniqueName ( name : string ) {
return currentSourceFile ? ts . isFileLevelUniqueName ( currentSourceFile , name , hasGlobalName ) : true ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Returns a value indicating whether a name is unique within a container .
* /
function isUniqueLocalName ( name : string , container : Node ) : boolean {
for ( let node = container ; isNodeDescendantOf ( node , container ) ; node = node . nextContainer ! ) {
if ( node . locals ) {
const local = node . locals . get ( escapeLeadingUnderscores ( name ) ) ;
// We conservatively include alias symbols to cover cases where they're emitted as locals
if ( local && local . flags & ( SymbolFlags . Value | SymbolFlags . ExportValue | SymbolFlags . Alias ) ) {
return false ;
}
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
return true ;
}
2016-01-27 07:59:34 +01:00
2021-02-26 08:01:41 +01:00
/ * *
* Return the next available name in the pattern _a . . . _z , _0 , _1 , . . .
* TempFlags . _i or TempFlags . _n may be used to express a preference for that dedicated name .
* Note that names generated by makeTempVariableName and makeUniqueName will never conflict .
* /
function makeTempVariableName ( flags : TempFlags , reservedInNestedScopes? : boolean ) : string {
if ( flags && ! ( tempFlags & flags ) ) {
const name = flags === TempFlags . _i ? "_i" : "_n" ;
if ( isUniqueName ( name ) ) {
tempFlags |= flags ;
if ( reservedInNestedScopes ) {
reserveNameInNestedScopes ( name ) ;
}
return name ;
2015-06-18 23:01:49 +02:00
}
}
2021-02-26 08:01:41 +01:00
while ( true ) {
const count = tempFlags & TempFlags . CountMask ;
tempFlags ++ ;
// Skip over 'i' and 'n'
if ( count !== 8 && count !== 13 ) {
const name = count < 26
? "_" + String . fromCharCode ( CharacterCodes . a + count )
: "_" + ( count - 26 ) ;
if ( isUniqueName ( name ) ) {
if ( reservedInNestedScopes ) {
reserveNameInNestedScopes ( name ) ;
}
return name ;
2015-04-02 02:58:28 +02:00
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
}
}
2015-07-09 23:44:47 +02:00
2021-02-26 08:01:41 +01:00
/ * *
* Generate a name that is unique within the current file and doesn ' t conflict with any names
* in global scope . The name is formed by adding an '_n' suffix to the specified base name ,
* where n is a positive integer . Note that names generated by makeTempVariableName and
* makeUniqueName are guaranteed to never conflict .
* If ` optimistic ` is set , the first instance will use 'baseName' verbatim instead of 'baseName_1'
* /
function makeUniqueName ( baseName : string , checkFn : ( name : string ) = > boolean = isUniqueName , optimistic? : boolean , scoped? : boolean ) : string {
if ( optimistic ) {
if ( checkFn ( baseName ) ) {
if ( scoped ) {
reserveNameInNestedScopes ( baseName ) ;
2020-11-02 23:24:55 +01:00
}
else {
2021-02-26 08:01:41 +01:00
generatedNames . add ( baseName ) ;
2020-11-02 23:24:55 +01:00
}
2021-02-26 08:01:41 +01:00
return baseName ;
2014-07-12 00:13:01 +02:00
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
// Find the first unique 'name_n', where n is a positive number
if ( baseName . charCodeAt ( baseName . length - 1 ) !== CharacterCodes . _ ) {
baseName += "_" ;
2017-03-15 19:44:36 +01:00
}
2021-02-26 08:01:41 +01:00
let i = 1 ;
while ( true ) {
const generatedName = baseName + i ;
if ( checkFn ( generatedName ) ) {
if ( scoped ) {
reserveNameInNestedScopes ( generatedName ) ;
}
else {
generatedNames . add ( generatedName ) ;
}
return generatedName ;
Much better comment preservation (#22141)
* Retain comments on (and produce sourcemaps on) the equals token in initializers
* Improved comments/sourcemaps for await, yield, while, and for
* Retain comments on block curly-braces
* Emit comments for if statements
* Improved switch case comment emit
* Improve comment and sourcemap emit for try/catch, throw, and continue statements
* Improve sourcemap emit and comments for with statements
* More accurate sourcemaps+comments emit for new, typeof, void, and delete
* Improve comment emit for element access expressions
* Preserve more comments on imports and exports
* Make function a bit more defensive like other usages of emitTrailingCommentsOfPosition
* Support preserving comments within empty lists
* Handle leading comments of tokens, conditionally indent leading comments
* Stop heuristically sourcemapping tokens
When the transform was trivial it worked, but was unneeded, but when it was complex, it was brittle - best leave source mapping up to the transformers
* Fix unneeded +1
* Tighten up element access comments
* Handle comments on parenthesized expression tokens
* Fix nit
2018-03-03 02:23:59 +01:00
}
2021-02-26 08:01:41 +01:00
i ++ ;
2014-07-13 01:04:16 +02:00
}
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2021-02-26 08:01:41 +01:00
function makeFileLevelOptimisticUniqueName ( name : string ) {
return makeUniqueName ( name , isFileLevelUniqueName , /*optimistic*/ true ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique name for a ModuleDeclaration or EnumDeclaration .
* /
function generateNameForModuleOrEnum ( node : ModuleDeclaration | EnumDeclaration ) {
const name = getTextOfNode ( node . name ) ;
// Use module/enum name itself if it is unique, otherwise make a unique variation
return isUniqueLocalName ( name , node ) ? name : makeUniqueName ( name ) ;
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique name for an ImportDeclaration or ExportDeclaration .
* /
function generateNameForImportOrExportDeclaration ( node : ImportDeclaration | ExportDeclaration ) {
const expr = getExternalModuleName ( node ) ! ; // TODO: GH#18217
const baseName = isStringLiteral ( expr ) ?
makeIdentifierFromModuleName ( expr . text ) : "module" ;
return makeUniqueName ( baseName ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique name for a default export .
* /
function generateNameForExportDefault() {
return makeUniqueName ( "default" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique name for a class expression .
* /
function generateNameForClassExpression() {
return makeUniqueName ( "class" ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
function generateNameForMethodOrAccessor ( node : MethodDeclaration | AccessorDeclaration ) {
if ( isIdentifier ( node . name ) ) {
return generateNameCached ( node . name ) ;
}
return makeTempVariableName ( TempFlags . Auto ) ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique name from a node .
* /
function generateNameForNode ( node : Node , flags? : GeneratedIdentifierFlags ) : string {
switch ( node . kind ) {
case SyntaxKind . Identifier :
return makeUniqueName (
getTextOfNode ( node ) ,
isUniqueName ,
! ! ( flags ! & GeneratedIdentifierFlags . Optimistic ) ,
! ! ( flags ! & GeneratedIdentifierFlags . ReservedInNestedScopes )
) ;
case SyntaxKind . ModuleDeclaration :
case SyntaxKind . EnumDeclaration :
2021-05-18 15:20:57 +02:00
return generateNameForModuleOrEnum ( node as ModuleDeclaration | EnumDeclaration ) ;
2021-02-26 08:01:41 +01:00
case SyntaxKind . ImportDeclaration :
case SyntaxKind . ExportDeclaration :
2021-05-18 15:20:57 +02:00
return generateNameForImportOrExportDeclaration ( node as ImportDeclaration | ExportDeclaration ) ;
2021-02-26 08:01:41 +01:00
case SyntaxKind . FunctionDeclaration :
case SyntaxKind . ClassDeclaration :
case SyntaxKind . ExportAssignment :
return generateNameForExportDefault ( ) ;
case SyntaxKind . ClassExpression :
return generateNameForClassExpression ( ) ;
case SyntaxKind . MethodDeclaration :
case SyntaxKind . GetAccessor :
case SyntaxKind . SetAccessor :
2021-05-18 15:20:57 +02:00
return generateNameForMethodOrAccessor ( node as MethodDeclaration | AccessorDeclaration ) ;
2021-02-26 08:01:41 +01:00
case SyntaxKind . ComputedPropertyName :
return makeTempVariableName ( TempFlags . Auto , /*reserveInNestedScopes*/ true ) ;
default :
return makeTempVariableName ( TempFlags . Auto ) ;
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Generates a unique identifier for a node .
* /
function makeName ( name : GeneratedIdentifier ) {
switch ( name . autoGenerateFlags & GeneratedIdentifierFlags . KindMask ) {
case GeneratedIdentifierFlags . Auto :
return makeTempVariableName ( TempFlags . Auto , ! ! ( name . autoGenerateFlags & GeneratedIdentifierFlags . ReservedInNestedScopes ) ) ;
case GeneratedIdentifierFlags . Loop :
return makeTempVariableName ( TempFlags . _i , ! ! ( name . autoGenerateFlags & GeneratedIdentifierFlags . ReservedInNestedScopes ) ) ;
case GeneratedIdentifierFlags . Unique :
return makeUniqueName (
idText ( name ) ,
( name . autoGenerateFlags & GeneratedIdentifierFlags . FileLevel ) ? isFileLevelUniqueName : isUniqueName ,
! ! ( name . autoGenerateFlags & GeneratedIdentifierFlags . Optimistic ) ,
! ! ( name . autoGenerateFlags & GeneratedIdentifierFlags . ReservedInNestedScopes )
) ;
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
2021-02-26 08:01:41 +01:00
return Debug . fail ( "Unsupported GeneratedIdentifierKind." ) ;
2018-08-22 21:42:36 +02:00
}
2021-02-26 08:01:41 +01:00
/ * *
* Gets the node from which a name should be generated .
* /
function getNodeForGeneratedName ( name : GeneratedIdentifier ) {
const autoGenerateId = name . autoGenerateId ;
let node = name as Node ;
let original = node . original ;
while ( original ) {
node = original ;
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
2021-02-26 08:01:41 +01:00
// if "node" is a different generated name (having a different
// "autoGenerateId"), use it and stop traversing.
if ( isIdentifier ( node )
&& ! ! ( node . autoGenerateFlags ! & GeneratedIdentifierFlags . Node )
&& node . autoGenerateId !== autoGenerateId ) {
break ;
}
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter
* Unification of writers is done-ish
* Make node builder support more flags
* Write out mixins like we used to
* Accept prototype-free baselines
* Use instantiated constraint when building mapped type nodes
* Accept better mapped type baselines
* Report inaccessible this in node builder
* Turns out there was a bug in our codefix, too
* Symbol display builder usage falling
* Replace signatureToString with a nodeBuilder solution
* Replace the last internal usages of the symbol writer
* Accept semicolon additions
* Accept updated symbol baseline output
* Start using node builder for some LS operations
* Remove those pesky trailing semicolons on signatures
* Get signature printing much closer to old output
* Parameter lists should not be indented by default, especially when single-line
* Signatures up to snuff
* Type quickinfo emit is up to snuff
* Start of symbol writer replacement, needs a bit more for full compat
* Slightly mor accurate to old behavior
* Replicate qualified name type argument output correctly
* Bring back the old symbol baselines
* Mostly identical to old symbol emit now
* Perfectly matches old behavior thus far
* Replace another usage of the symbol builder
* Another usage removed
* Another usage removed
* Remove final uses of symbol display builder
* Remove implementation and types for unused symbol display builder
* Cleanup in the checker
* monomorphize new emitter code
* Replace emitWithSuffix
* Push space character to interface with writer
* List emit
* Fix lack of usage of emitExpression
* writeList, not printList
* Remove listy writes and replace with new printer calls
* Move ListFormat into types.ts
* Remove most new XToString functions in favor of node builder functions
* Accept API breaks
* Add getSymbolDisplayBuilder polyfill
* Accept updated API baseline
* Move definition to make diff easier to read
* Reinternalize some things
* Remove trailign whitespace
* Reorder for zero diff
* Remove newline
* Make shim mor eperfectly imitate old behavior
* Style feedback
* Rename reset to clear to maintain backcompat with SymbolWriter
* Fix quickfix
* Keep EmitTextWriter internal
* Remove EmitTextWriter from public API
* Mimic default name declaration emit fix
* Fix tests broken by merge
* use isFunctionLike
* Cleanup, sync TypeFormat and NodeBuilder flags
* Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism
* Use variable instead of ternary
* Write helper for emitNodeWithWriter
* Emitter cleanup
* Cleanup whitespace, comment
* Reuse printer
* Raise error if display parts writer uses rawWrite
* Hide writer parameter through different function instead of overload, rename function in emitter
* Make less printer
* fix lint
2018-01-16 18:53:42 +01:00
2021-02-26 08:01:41 +01:00
original = node . original ;
2020-03-19 17:46:00 +01:00
}
2017-01-30 21:27:24 +01:00
2021-02-26 08:01:41 +01:00
// otherwise, return the original node for the source;
return node ;
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
// Comments
2016-12-05 21:30:14 +01:00
2021-04-19 18:34:46 +02:00
function pipelineEmitWithComments ( hint : EmitHint , node : Node ) {
const pipelinePhase = getNextPipelinePhase ( PipelinePhase . Comments , hint , node ) ;
const savedContainerPos = containerPos ;
const savedContainerEnd = containerEnd ;
const savedDeclarationListContainerEnd = declarationListContainerEnd ;
emitCommentsBeforeNode ( node ) ;
pipelinePhase ( hint , node ) ;
emitCommentsAfterNode ( node , savedContainerPos , savedContainerEnd , savedDeclarationListContainerEnd ) ;
}
function emitCommentsBeforeNode ( node : Node ) {
const emitFlags = getEmitFlags ( node ) ;
const commentRange = getCommentRange ( node ) ;
// Emit leading comments
emitLeadingCommentsOfNode ( node , emitFlags , commentRange . pos , commentRange . end ) ;
if ( emitFlags & EmitFlags . NoNestedComments ) {
commentsDisabled = true ;
}
}
function emitCommentsAfterNode ( node : Node , savedContainerPos : number , savedContainerEnd : number , savedDeclarationListContainerEnd : number ) {
const emitFlags = getEmitFlags ( node ) ;
const commentRange = getCommentRange ( node ) ;
// Emit trailing comments
if ( emitFlags & EmitFlags . NoNestedComments ) {
commentsDisabled = false ;
}
emitTrailingCommentsOfNode ( node , emitFlags , commentRange . pos , commentRange . end , savedContainerPos , savedContainerEnd , savedDeclarationListContainerEnd ) ;
}
2021-02-26 08:01:41 +01:00
function emitLeadingCommentsOfNode ( node : Node , emitFlags : EmitFlags , pos : number , end : number ) {
enterComment ( ) ;
hasWrittenComment = false ;
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
// We have to explicitly check that the node is JsxText because if the compilerOptions.jsx is "preserve" we will not do any transformation.
// It is expensive to walk entire tree just to set one kind of node to have no comments.
const skipLeadingComments = pos < 0 || ( emitFlags & EmitFlags . NoLeadingComments ) !== 0 || node . kind === SyntaxKind . JsxText ;
const skipTrailingComments = end < 0 || ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 || node . kind === SyntaxKind . JsxText ;
// Save current container state on the stack.
if ( ( pos > 0 || end > 0 ) && pos !== end ) {
// Emit leading comments if the position is not synthesized and the node
// has not opted out from emitting leading comments.
if ( ! skipLeadingComments ) {
emitLeadingComments ( pos , /*isEmittedNode*/ node . kind !== SyntaxKind . NotEmittedStatement ) ;
}
if ( ! skipLeadingComments || ( pos >= 0 && ( emitFlags & EmitFlags . NoLeadingComments ) !== 0 ) ) {
// Advance the container position if comments get emitted or if they've been disabled explicitly using NoLeadingComments.
containerPos = pos ;
}
if ( ! skipTrailingComments || ( end >= 0 && ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 ) ) {
// As above.
containerEnd = end ;
// To avoid invalid comment emit in a down-level binding pattern, we
// keep track of the last declaration list container's end
if ( node . kind === SyntaxKind . VariableDeclarationList ) {
declarationListContainerEnd = end ;
}
}
2017-05-19 19:18:42 +02:00
}
2021-02-26 08:01:41 +01:00
forEach ( getSyntheticLeadingComments ( node ) , emitLeadingSynthesizedComment ) ;
exitComment ( ) ;
2017-05-19 19:18:42 +02:00
}
2021-02-26 08:01:41 +01:00
function emitTrailingCommentsOfNode ( node : Node , emitFlags : EmitFlags , pos : number , end : number , savedContainerPos : number , savedContainerEnd : number , savedDeclarationListContainerEnd : number ) {
enterComment ( ) ;
const skipTrailingComments = end < 0 || ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 || node . kind === SyntaxKind . JsxText ;
forEach ( getSyntheticTrailingComments ( node ) , emitTrailingSynthesizedComment ) ;
if ( ( pos > 0 || end > 0 ) && pos !== end ) {
// Restore previous container state.
containerPos = savedContainerPos ;
containerEnd = savedContainerEnd ;
declarationListContainerEnd = savedDeclarationListContainerEnd ;
// Emit trailing comments if the position is not synthesized and the node
// has not opted out from emitting leading comments and is an emitted node.
if ( ! skipTrailingComments && node . kind !== SyntaxKind . NotEmittedStatement ) {
emitTrailingComments ( end ) ;
}
}
exitComment ( ) ;
2016-06-07 19:32:03 +02:00
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
function emitLeadingSynthesizedComment ( comment : SynthesizedComment ) {
if ( comment . hasLeadingNewline || comment . kind === SyntaxKind . SingleLineCommentTrivia ) {
writer . writeLine ( ) ;
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
writeSynthesizedComment ( comment ) ;
if ( comment . hasTrailingNewLine || comment . kind === SyntaxKind . SingleLineCommentTrivia ) {
writer . writeLine ( ) ;
2020-06-26 23:48:19 +02:00
}
2017-01-30 21:27:24 +01:00
else {
2021-02-26 08:01:41 +01:00
writer . writeSpace ( " " ) ;
2017-01-30 21:27:24 +01:00
}
}
2021-02-26 08:01:41 +01:00
function emitTrailingSynthesizedComment ( comment : SynthesizedComment ) {
if ( ! writer . isAtStartOfLine ( ) ) {
writer . writeSpace ( " " ) ;
}
writeSynthesizedComment ( comment ) ;
if ( comment . hasTrailingNewLine ) {
writer . writeLine ( ) ;
2017-01-30 21:27:24 +01:00
}
}
2021-02-26 08:01:41 +01:00
function writeSynthesizedComment ( comment : SynthesizedComment ) {
const text = formatSynthesizedComment ( comment ) ;
const lineMap = comment . kind === SyntaxKind . MultiLineCommentTrivia ? computeLineStarts ( text ) : undefined ;
writeCommentRange ( text , lineMap ! , writer , 0 , text . length , newLine ) ;
2016-06-07 19:32:03 +02:00
}
2015-07-30 20:11:36 +02:00
2021-02-26 08:01:41 +01:00
function formatSynthesizedComment ( comment : SynthesizedComment ) {
return comment . kind === SyntaxKind . MultiLineCommentTrivia
? ` /* ${ comment . text } */ `
: ` // ${ comment . text } ` ;
2016-06-07 19:32:03 +02:00
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
function emitBodyWithDetachedComments ( node : Node , detachedRange : TextRange , emitCallback : ( node : Node ) = > void ) {
enterComment ( ) ;
const { pos , end } = detachedRange ;
const emitFlags = getEmitFlags ( node ) ;
const skipLeadingComments = pos < 0 || ( emitFlags & EmitFlags . NoLeadingComments ) !== 0 ;
const skipTrailingComments = commentsDisabled || end < 0 || ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 ;
if ( ! skipLeadingComments ) {
emitDetachedCommentsAndUpdateCommentsInfo ( detachedRange ) ;
}
2015-01-23 00:58:00 +01:00
2021-02-26 08:01:41 +01:00
exitComment ( ) ;
if ( emitFlags & EmitFlags . NoNestedComments && ! commentsDisabled ) {
commentsDisabled = true ;
emitCallback ( node ) ;
commentsDisabled = false ;
}
else {
emitCallback ( node ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-18 02:34:42 +01:00
2021-02-26 08:01:41 +01:00
enterComment ( ) ;
if ( ! skipTrailingComments ) {
emitLeadingComments ( detachedRange . end , /*isEmittedNode*/ true ) ;
if ( hasWrittenComment && ! writer . isAtStartOfLine ( ) ) {
writer . writeLine ( ) ;
2014-08-07 03:42:14 +02:00
}
2014-07-17 00:39:14 +02:00
}
2021-02-26 08:01:41 +01:00
exitComment ( ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-17 00:39:14 +02:00
2021-06-04 16:46:23 +02:00
function originalNodesHaveSameParent ( nodeA : Node , nodeB : Node ) {
nodeA = getOriginalNode ( nodeA ) ;
// For performance, do not call `getOriginalNode` for `nodeB` if `nodeA` doesn't even
// have a parent node.
return nodeA . parent && nodeA . parent === getOriginalNode ( nodeB ) . parent ;
}
2021-02-26 19:37:51 +01:00
2021-06-04 16:46:23 +02:00
function siblingNodePositionsAreComparable ( previousNode : Node , nextNode : Node ) {
2021-02-26 19:37:51 +01:00
if ( nextNode . pos < previousNode . end ) {
return false ;
}
previousNode = getOriginalNode ( previousNode ) ;
nextNode = getOriginalNode ( nextNode ) ;
const parent = previousNode . parent ;
if ( ! parent || parent !== nextNode . parent ) {
return false ;
}
const parentNodeArray = getContainingNodeArray ( previousNode ) ;
const prevNodeIndex = parentNodeArray ? . indexOf ( previousNode ) ;
return prevNodeIndex !== undefined && prevNodeIndex > - 1 && parentNodeArray ! . indexOf ( nextNode ) === prevNodeIndex + 1 ;
}
2021-02-26 08:01:41 +01:00
function emitLeadingComments ( pos : number , isEmittedNode : boolean ) {
hasWrittenComment = false ;
2014-07-13 01:04:16 +02:00
2021-02-26 08:01:41 +01:00
if ( isEmittedNode ) {
if ( pos === 0 && currentSourceFile ? . isDeclarationFile ) {
forEachLeadingCommentToEmit ( pos , emitNonTripleSlashLeadingComment ) ;
2014-07-17 00:39:14 +02:00
}
2021-02-26 08:01:41 +01:00
else {
forEachLeadingCommentToEmit ( pos , emitLeadingComment ) ;
2015-03-18 03:25:40 +01:00
}
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
else if ( pos === 0 ) {
// If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node,
// unless it is a triple slash comment at the top of the file.
// For Example:
// /// <reference-path ...>
// declare var x;
// /// <reference-path ...>
// interface F {}
// The first /// will NOT be removed while the second one will be removed even though both node will not be emitted
forEachLeadingCommentToEmit ( pos , emitTripleSlashLeadingComment ) ;
2020-04-22 00:34:30 +02:00
}
}
2021-02-26 08:01:41 +01:00
function emitTripleSlashLeadingComment ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) {
if ( isTripleSlashComment ( commentPos , commentEnd ) ) {
emitLeadingComment ( commentPos , commentEnd , kind , hasTrailingNewLine , rangePos ) ;
2020-04-22 00:34:30 +02:00
}
}
2021-02-26 08:01:41 +01:00
function emitNonTripleSlashLeadingComment ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) {
if ( ! isTripleSlashComment ( commentPos , commentEnd ) ) {
emitLeadingComment ( commentPos , commentEnd , kind , hasTrailingNewLine , rangePos ) ;
2014-07-17 00:39:14 +02:00
}
2021-02-26 08:01:41 +01:00
}
2014-08-07 02:58:03 +02:00
2021-02-26 08:01:41 +01:00
function shouldWriteComment ( text : string , pos : number ) {
if ( printerOptions . onlyPrintJsDocStyle ) {
return ( isJSDocLikeText ( text , pos ) || isPinnedComment ( text , pos ) ) ;
}
return true ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitLeadingComment ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) {
if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
if ( ! hasWrittenComment ) {
emitNewLineBeforeLeadingCommentOfPosition ( getCurrentLineMap ( ) , writer , rangePos , commentPos ) ;
hasWrittenComment = true ;
2019-09-30 21:33:28 +02:00
}
2021-02-26 08:01:41 +01:00
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
emitPos ( commentPos ) ;
writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
emitPos ( commentEnd ) ;
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
if ( hasTrailingNewLine ) {
writer . writeLine ( ) ;
}
else if ( kind === SyntaxKind . MultiLineCommentTrivia ) {
writer . writeSpace ( " " ) ;
2020-03-19 17:46:00 +01:00
}
2021-02-26 08:01:41 +01:00
}
2020-03-19 17:46:00 +01:00
2021-02-26 08:01:41 +01:00
function emitLeadingCommentsOfPosition ( pos : number ) {
if ( commentsDisabled || pos === - 1 ) {
return ;
2015-03-18 02:34:42 +01:00
}
2021-02-26 08:01:41 +01:00
emitLeadingComments ( pos , /*isEmittedNode*/ true ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
function emitTrailingComments ( pos : number ) {
forEachTrailingCommentToEmit ( pos , emitTrailingComment ) ;
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
function emitTrailingComment ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
if ( ! writer . isAtStartOfLine ( ) ) {
writer . writeSpace ( " " ) ;
2015-03-18 02:34:42 +01:00
}
2021-02-26 08:01:41 +01:00
emitPos ( commentPos ) ;
writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
emitPos ( commentEnd ) ;
2016-06-07 19:32:03 +02:00
2021-02-26 08:01:41 +01:00
if ( hasTrailingNewLine ) {
writer . writeLine ( ) ;
2015-03-18 02:34:42 +01:00
}
2016-06-07 19:32:03 +02:00
}
2015-10-01 00:45:23 +02:00
2021-02-26 08:01:41 +01:00
function emitTrailingCommentsOfPosition ( pos : number , prefixSpace? : boolean , forceNoNewline? : boolean ) {
if ( commentsDisabled ) {
return ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
enterComment ( ) ;
forEachTrailingCommentToEmit ( pos , prefixSpace ? emitTrailingComment : forceNoNewline ? emitTrailingCommentOfPositionNoNewline : emitTrailingCommentOfPosition ) ;
exitComment ( ) ;
}
2015-03-18 02:34:42 +01:00
2021-02-26 08:01:41 +01:00
function emitTrailingCommentOfPositionNoNewline ( commentPos : number , commentEnd : number , kind : SyntaxKind ) {
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
2020-08-31 23:17:09 +02:00
2021-02-26 08:01:41 +01:00
emitPos ( commentPos ) ;
writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
emitPos ( commentEnd ) ;
2015-03-18 02:34:42 +01:00
2021-02-26 08:01:41 +01:00
if ( kind === SyntaxKind . SingleLineCommentTrivia ) {
writer . writeLine ( ) ; // still write a newline for single-line comments, so closing tokens aren't written on the same line
2017-11-06 21:51:34 +01:00
}
2016-10-04 04:05:12 +02:00
}
2021-02-26 08:01:41 +01:00
function emitTrailingCommentOfPosition ( commentPos : number , commentEnd : number , _kind : SyntaxKind , hasTrailingNewLine : boolean ) {
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
emitPos ( commentPos ) ;
writeCommentRange ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , commentPos , commentEnd , newLine ) ;
emitPos ( commentEnd ) ;
if ( hasTrailingNewLine ) {
writer . writeLine ( ) ;
}
else {
writer . writeSpace ( " " ) ;
2017-11-06 21:51:34 +01:00
}
2018-01-16 21:33:55 +01:00
}
2021-02-26 08:01:41 +01:00
function forEachLeadingCommentToEmit ( pos : number , cb : ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) = > void ) {
// Emit the leading comments only if the container's pos doesn't match because the container should take care of emitting these comments
if ( currentSourceFile && ( containerPos === - 1 || pos !== containerPos ) ) {
if ( hasDetachedComments ( pos ) ) {
forEachLeadingCommentWithoutDetachedComments ( cb ) ;
}
else {
forEachLeadingCommentRange ( currentSourceFile . text , pos , cb , /*state*/ pos ) ;
}
2018-01-16 21:33:55 +01:00
}
2017-01-30 21:27:24 +01:00
}
2021-02-26 08:01:41 +01:00
function forEachTrailingCommentToEmit ( end : number , cb : ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean ) = > void ) {
// Emit the trailing comments only if the container's end doesn't match because the container should take care of emitting these comments
if ( currentSourceFile && ( containerEnd === - 1 || ( end !== containerEnd && end !== declarationListContainerEnd ) ) ) {
forEachTrailingCommentRange ( currentSourceFile . text , end , cb ) ;
2018-05-02 22:34:14 +02:00
}
}
2021-02-26 08:01:41 +01:00
function hasDetachedComments ( pos : number ) {
return detachedCommentsInfo !== undefined && last ( detachedCommentsInfo ) . nodePos === pos ;
}
function forEachLeadingCommentWithoutDetachedComments ( cb : ( commentPos : number , commentEnd : number , kind : SyntaxKind , hasTrailingNewLine : boolean , rangePos : number ) = > void ) {
// get the leading comments from detachedPos
const pos = last ( detachedCommentsInfo ! ) . detachedCommentEndPos ;
if ( detachedCommentsInfo ! . length - 1 ) {
detachedCommentsInfo ! . pop ( ) ;
}
else {
detachedCommentsInfo = undefined ;
2018-05-02 22:34:14 +02:00
}
2021-02-26 08:01:41 +01:00
forEachLeadingCommentRange ( currentSourceFile ! . text , pos , cb , /*state*/ pos ) ;
2018-05-02 22:34:14 +02:00
}
2021-02-26 08:01:41 +01:00
function emitDetachedCommentsAndUpdateCommentsInfo ( range : TextRange ) {
const currentDetachedCommentInfo = emitDetachedComments ( currentSourceFile ! . text , getCurrentLineMap ( ) , writer , emitComment , range , newLine , commentsDisabled ) ;
if ( currentDetachedCommentInfo ) {
if ( detachedCommentsInfo ) {
detachedCommentsInfo . push ( currentDetachedCommentInfo ) ;
2018-05-02 22:34:14 +02:00
}
2021-02-26 08:01:41 +01:00
else {
detachedCommentsInfo = [ currentDetachedCommentInfo ] ;
2018-05-02 22:34:14 +02:00
}
}
}
2021-02-26 08:01:41 +01:00
function emitComment ( text : string , lineMap : number [ ] , writer : EmitTextWriter , commentPos : number , commentEnd : number , newLine : string ) {
if ( ! shouldWriteComment ( currentSourceFile ! . text , commentPos ) ) return ;
emitPos ( commentPos ) ;
writeCommentRange ( text , lineMap , writer , commentPos , commentEnd , newLine ) ;
emitPos ( commentEnd ) ;
}
2017-01-30 21:27:24 +01:00
/ * *
2021-02-26 08:01:41 +01:00
* Determine if the given comment is a triple - slash
*
* @return true if the comment is a triple - slash comment else false
2017-01-30 21:27:24 +01:00
* /
2021-02-26 08:01:41 +01:00
function isTripleSlashComment ( commentPos : number , commentEnd : number ) {
return isRecognizedTripleSlashComment ( currentSourceFile ! . text , commentPos , commentEnd ) ;
2016-06-07 19:32:03 +02:00
}
2015-03-18 02:34:42 +01:00
2021-02-26 08:01:41 +01:00
// Source Maps
function getParsedSourceMap ( node : UnparsedSource ) {
if ( node . parsedSourceMap === undefined && node . sourceMapText !== undefined ) {
node . parsedSourceMap = tryParseRawSourceMap ( node . sourceMapText ) || false ;
}
return node . parsedSourceMap || undefined ;
2017-01-30 21:27:24 +01:00
}
2021-04-19 18:34:46 +02:00
function pipelineEmitWithSourceMaps ( hint : EmitHint , node : Node ) {
const pipelinePhase = getNextPipelinePhase ( PipelinePhase . SourceMaps , hint , node ) ;
emitSourceMapsBeforeNode ( node ) ;
pipelinePhase ( hint , node ) ;
emitSourceMapsAfterNode ( node ) ;
}
function emitSourceMapsBeforeNode ( node : Node ) {
const emitFlags = getEmitFlags ( node ) ;
const sourceMapRange = getSourceMapRange ( node ) ;
// Emit leading sourcemap
if ( isUnparsedNode ( node ) ) {
Debug . assertIsDefined ( node . parent , "UnparsedNodes must have parent pointers" ) ;
const parsed = getParsedSourceMap ( node . parent ) ;
if ( parsed && sourceMapGenerator ) {
sourceMapGenerator . appendSourceMap (
writer . getLine ( ) ,
writer . getColumn ( ) ,
parsed ,
node . parent . sourceMapPath ! ,
node . parent . getLineAndCharacterOfPosition ( node . pos ) ,
node . parent . getLineAndCharacterOfPosition ( node . end )
) ;
}
}
else {
const source = sourceMapRange . source || sourceMapSource ;
if ( node . kind !== SyntaxKind . NotEmittedStatement
&& ( emitFlags & EmitFlags . NoLeadingSourceMap ) === 0
&& sourceMapRange . pos >= 0 ) {
emitSourcePos ( sourceMapRange . source || sourceMapSource , skipSourceTrivia ( source , sourceMapRange . pos ) ) ;
}
if ( emitFlags & EmitFlags . NoNestedSourceMaps ) {
sourceMapsDisabled = true ;
}
}
}
function emitSourceMapsAfterNode ( node : Node ) {
const emitFlags = getEmitFlags ( node ) ;
const sourceMapRange = getSourceMapRange ( node ) ;
// Emit trailing sourcemap
if ( ! isUnparsedNode ( node ) ) {
if ( emitFlags & EmitFlags . NoNestedSourceMaps ) {
sourceMapsDisabled = false ;
}
if ( node . kind !== SyntaxKind . NotEmittedStatement
&& ( emitFlags & EmitFlags . NoTrailingSourceMap ) === 0
&& sourceMapRange . end >= 0 ) {
emitSourcePos ( sourceMapRange . source || sourceMapSource , sourceMapRange . end ) ;
}
}
}
2017-01-30 21:27:24 +01:00
/ * *
2021-02-26 08:01:41 +01:00
* Skips trivia such as comments and white - space that can be optionally overridden by the source - map source
2017-01-30 21:27:24 +01:00
* /
2021-02-26 08:01:41 +01:00
function skipSourceTrivia ( source : SourceMapSource , pos : number ) : number {
return source . skipTrivia ? source . skipTrivia ( pos ) : skipTrivia ( source . text , pos ) ;
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
2018-03-31 02:43:37 +02:00
/ * *
2021-02-26 08:01:41 +01:00
* Emits a mapping .
*
* If the position is synthetic ( undefined or a negative value ) , no mapping will be
* created .
*
* @param pos The position .
2018-03-31 02:43:37 +02:00
* /
2021-02-26 08:01:41 +01:00
function emitPos ( pos : number ) {
if ( sourceMapsDisabled || positionIsSynthesized ( pos ) || isJsonSourceMapSource ( sourceMapSource ) ) {
return ;
}
const { line : sourceLine , character : sourceCharacter } = getLineAndCharacterOfPosition ( sourceMapSource , pos ) ;
sourceMapGenerator ! . addMapping (
writer . getLine ( ) ,
writer . getColumn ( ) ,
sourceMapSourceIndex ,
sourceLine ,
sourceCharacter ,
/*nameIndex*/ undefined ) ;
2018-03-31 02:43:37 +02:00
}
2021-02-26 08:01:41 +01:00
function emitSourcePos ( source : SourceMapSource , pos : number ) {
if ( source !== sourceMapSource ) {
const savedSourceMapSource = sourceMapSource ;
const savedSourceMapSourceIndex = sourceMapSourceIndex ;
setSourceMapSource ( source ) ;
emitPos ( pos ) ;
resetSourceMapSource ( savedSourceMapSource , savedSourceMapSourceIndex ) ;
}
else {
emitPos ( pos ) ;
2015-08-07 02:20:35 +02:00
}
2016-06-07 19:32:03 +02:00
}
2015-08-07 02:20:35 +02:00
2016-06-07 19:32:03 +02:00
/ * *
2021-02-26 08:01:41 +01:00
* Emits a token of a node with possible leading and trailing source maps .
*
* @param node The node containing the token .
* @param token The token to emit .
* @param tokenStartPos The start pos of the token .
* @param emitCallback The callback used to emit the token .
2017-01-30 21:27:24 +01:00
* /
2021-02-26 08:01:41 +01:00
function emitTokenWithSourceMap ( node : Node | undefined , token : SyntaxKind , writer : ( s : string ) = > void , tokenPos : number , emitCallback : ( token : SyntaxKind , writer : ( s : string ) = > void , tokenStartPos : number ) = > number ) {
if ( sourceMapsDisabled || node && isInJsonFile ( node ) ) {
return emitCallback ( token , writer , tokenPos ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
const emitNode = node && node . emitNode ;
const emitFlags = emitNode && emitNode . flags || EmitFlags . None ;
const range = emitNode && emitNode . tokenSourceMapRanges && emitNode . tokenSourceMapRanges [ token ] ;
const source = range && range . source || sourceMapSource ;
tokenPos = skipSourceTrivia ( source , range ? range.pos : tokenPos ) ;
if ( ( emitFlags & EmitFlags . NoTokenLeadingSourceMaps ) === 0 && tokenPos >= 0 ) {
emitSourcePos ( source , tokenPos ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
tokenPos = emitCallback ( token , writer , tokenPos ) ;
if ( range ) tokenPos = range . end ;
if ( ( emitFlags & EmitFlags . NoTokenTrailingSourceMaps ) === 0 && tokenPos >= 0 ) {
emitSourcePos ( source , tokenPos ) ;
}
return tokenPos ;
2016-06-07 19:32:03 +02:00
}
2015-09-01 05:33:02 +02:00
2021-02-26 08:01:41 +01:00
function setSourceMapSource ( source : SourceMapSource ) {
if ( sourceMapsDisabled ) {
return ;
2018-03-16 06:23:10 +01:00
}
2021-02-26 08:01:41 +01:00
sourceMapSource = source ;
if ( source === mostRecentlyAddedSourceMapSource ) {
// Fast path for when the new source map is the most recently added, in which case
// we use its captured index without going through the source map generator.
sourceMapSourceIndex = mostRecentlyAddedSourceMapSourceIndex ;
return ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
if ( isJsonSourceMapSource ( source ) ) {
return ;
}
sourceMapSourceIndex = sourceMapGenerator ! . addSource ( source . fileName ) ;
if ( printerOptions . inlineSources ) {
sourceMapGenerator ! . setSourceContent ( sourceMapSourceIndex , source . text ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
mostRecentlyAddedSourceMapSource = source ;
mostRecentlyAddedSourceMapSourceIndex = sourceMapSourceIndex ;
}
function resetSourceMapSource ( source : SourceMapSource , sourceIndex : number ) {
sourceMapSource = source ;
sourceMapSourceIndex = sourceIndex ;
}
function isJsonSourceMapSource ( sourceFile : SourceMapSource ) {
return fileExtensionIs ( sourceFile . fileName , Extension . Json ) ;
2016-06-07 19:32:03 +02:00
}
2021-02-26 08:01:41 +01:00
}
2017-01-30 21:27:24 +01:00
function createBracketsMap() {
const brackets : string [ ] [ ] = [ ] ;
brackets [ ListFormat . Braces ] = [ "{" , "}" ] ;
brackets [ ListFormat . Parenthesis ] = [ "(" , ")" ] ;
brackets [ ListFormat . AngleBrackets ] = [ "<" , ">" ] ;
brackets [ ListFormat . SquareBrackets ] = [ "[" , "]" ] ;
return brackets ;
}
2016-06-07 19:32:03 +02:00
2017-01-30 21:27:24 +01:00
function getOpeningBracket ( format : ListFormat ) {
return brackets [ format & ListFormat . BracketsMask ] [ 0 ] ;
}
2016-06-07 19:32:03 +02:00
2017-01-30 21:27:24 +01:00
function getClosingBracket ( format : ListFormat ) {
return brackets [ format & ListFormat . BracketsMask ] [ 1 ] ;
}
2016-06-07 19:32:03 +02:00
2017-01-30 21:27:24 +01:00
// Flags enum to track count of temp variables and a few dedicated names
const enum TempFlags {
2017-05-19 19:18:42 +02:00
Auto = 0x00000000 , // No preferred name
2017-01-30 21:27:24 +01:00
CountMask = 0x0FFFFFFF , // Temp variable counter
2017-05-19 19:18:42 +02:00
_i = 0x10000000 , // Use/preference flag for '_i'
2016-06-07 19:32:03 +02:00
}
2014-07-13 01:04:16 +02:00
}