How to use the ScriptTarget function from typescript
Find comprehensive JavaScript typescript.ScriptTarget code examples handpicked from public code repositorys.
typescript.ScriptTarget is an enumeration representing the target ECMAScript version for TypeScript compilation.
437 438 439 440 441 442 443 444 445 446
}; const sourceFile = ts.createSourceFile( 'index.ts', source, ts.ScriptTarget.ESNext, /* setParentNodes */ true, ); const result = ts.transform(sourceFile, [transformer]);
116
294
29
+ 3 other calls in file
139 140 141 142 143 144 145 146 147 148
// prodmode output to ES2015 so that we can generate the ES2015 flat ESM bundle. const downlevelToES2015Plugin = { name: 'downlevel-to-es2015', transform: (code, filePath) => { const compilerOptions = { target: ts.ScriptTarget.ES2015, module: ts.ModuleKind.ES2015, allowJs: true, sourceMap: true, downlevelIteration: true,
10
9
6
+ 9 other calls in file
How does typescript.ScriptTarget work?
typescript.ScriptTarget
is an enum that is used to specify the version of the ECMAScript standard for which a TypeScript file should be compiled, such as ES5 or ES2015, and it determines what language features are available to use.
17 18 19 20 21 22 23 24 25 26
; var callbackFuncResultStr = ") => "; var isExportingReact = false; var jsonObjMetaData = null; var tsDefaultOptions = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.ES2015, // moduleResolution: ts.ModuleResolutionKind.NodeJs, lib: ["DOM", "ES5", "ES6", "ES2015.Promise"], noImplicitAny: true,
3
4
4
+ 8 other calls in file
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
// declaration, and then writes the file back out (in memory to source) with // WebGLConstants being the first module. const node = typescript.createSourceFile( "Source/Cesium.d.ts", source, typescript.ScriptTarget.Latest ); let firstNode; node.forEachChild((child) => { if (
0
1
1
+ 1755 other calls in file
Ai Example
1 2 3 4 5 6 7
const ts = require("typescript"); const script = 'console.log("Hello, world!");'; const target = ts.ScriptTarget.ES5; const result = ts.transpile(script, { target }); console.log(result); // Output: "console.log(\"Hello, world!\");"
In this example, we're using the ScriptTarget enum to specify the target version of JavaScript that we want to transpile our code to. We set the target option to ts.ScriptTarget.ES5, which will transpile our code to ECMAScript 5.
23 24 25 26 27 28 29 30 31 32 33
}; function supportES2015(tsConfigPath) { if (!supportES2015.hasOwnProperty('supportES2015')) { const tsTarget = readTsConfig(tsConfigPath).options.target; supportES2015['supportES2015'] = tsTarget !== ts.ScriptTarget.ES3 && tsTarget !== ts.ScriptTarget.ES5; } return supportES2015['supportES2015']; }
0
0
1
+ 1156 other calls in file
12 13 14 15 16 17 18 19 20 21
var FILE_NAME = 'vscode://javascript/1'; // the same 'file' is used for all contents var JQUERY_D_TS = path_1.join(__dirname, '../../lib/jquery.d.ts'); var JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g; function getJavascriptMode(documentRegions) { var jsDocuments = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return documentRegions.get(document).getEmbeddedDocument('javascript'); }); var compilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es6.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic }; var currentTextDocument; var scriptFileVersion = 0; function updateCurrentTextDocument(doc) { if (!currentTextDocument || doc.uri !== currentTextDocument.uri || doc.version !== currentTextDocument.version) {
0
0
1
+ 182 other calls in file
23 24 25 26 27 28 29 30 31 32
noEmitOnError: useLibs, allowJs: true, newLine: ts.NewLineKind.LineFeed, moduleResolution: ts.ModuleResolutionKind.NodeJs, module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ESNext, skipLibCheck: true, sourceMap: false, importHelpers: true, experimentalDecorators: true,
0
0
1
119 120 121 122 123 124 125 126 127 128
const { options: compilerOptions } = read_tsconfig_1.readTsconfig(options.tsConfig, context.workspaceRoot); const target = compilerOptions.target || typescript_1.ScriptTarget.ES5; const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(sysProjectRoot); const isDifferentialLoadingNeeded = buildBrowserFeatures.isDifferentialLoadingNeeded(target); const differentialLoadingMode = !options.watch && isDifferentialLoadingNeeded; if (target > typescript_1.ScriptTarget.ES2015 && isDifferentialLoadingNeeded) { context.logger.warn(core_1.tags.stripIndent ` Warning: Using differential loading with targets ES5 and ES2016 or higher may cause problems. Browsers with support for ES2015 will load the ES2016+ scripts referenced with script[type="module"] but they may not support ES2016+ syntax.
0
0
1
+ 7 other calls in file
18 19 20 21 22 23 24 25 26 27
/** * True, when one or more browsers requires ES5 * support and the scirpt target is ES2015 or greater. */ isDifferentialLoadingNeeded(scriptTarget) { const es6TargetOrLater = scriptTarget > ts.ScriptTarget.ES5; return es6TargetOrLater && this.isEs5SupportNeeded(); } /** * True, when one or more browsers requires ES5 support
0
0
1
39 40 41 42 43 44 45 46 47 48
const tempFilename = 'bo-default-file.js'; const tempSourceFile = ts.createSourceFile(tempFilename, content, ts.ScriptTarget.Latest, allowFastPath); const parseDiagnostics = tempSourceFile.parseDiagnostics; const tsOptions = { // We target latest so that there is no downleveling. target: ts.ScriptTarget.Latest, isolatedModules: true, suppressOutputPathCheck: true, allowNonTsExtensions: true, noLib: true,
0
0
1
25 26 27 28 29 30 31 32 33 34
function execute(options, context, transforms = {}) { const root = context.workspaceRoot; // Check Angular version. version_1.assertCompatibleAngularVersion(root, context.logger); const tsConfig = read_tsconfig_1.readTsconfig(options.tsConfig, root); const target = tsConfig.options.target || typescript_1.ScriptTarget.ES5; const baseOutputPath = path.resolve(root, options.outputPath); let outputPaths; if (typeof options.bundleDependencies === 'string') { options.bundleDependencies = options.bundleDependencies === 'all';
0
0
1
+ 3 other calls in file
172 173 174 175 176 177 178 179 180 181
return rxjs_1.from(setup()).pipe(operators_1.switchMap(({ browserOptions, webpackConfig, projectRoot, locale }) => { const normalizedOptimization = utils_1.normalizeOptimization(browserOptions.optimization); if (browserOptions.index) { const { scripts = [], styles = [], baseHref, tsConfig } = browserOptions; const { options: compilerOptions } = read_tsconfig_1.readTsconfig(tsConfig, workspaceRoot); const target = compilerOptions.target || ts.ScriptTarget.ES5; const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot); const entrypoints = package_chunk_sort_1.generateEntryPoints({ scripts, styles }); const moduleEntrypoints = buildBrowserFeatures.isDifferentialLoadingNeeded(target) ? package_chunk_sort_1.generateEntryPoints({ scripts: [], styles })
0
0
1
typescript.SyntaxKind is the most popular function in typescript (82777 examples)