Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 54 additions & 37 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export const inverseJsxOptionMap = new Map(mapIterator(jsxOptionMap.entries(), (
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
// order also affects overload resolution when a type declared in one lib is
// augmented in another lib.
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
const libEntries: [string, string][] = [
// JavaScript only
["es5", "lib.es5.d.ts"],
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/transformers/esnext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const enum UsingKind {

/** @internal */
export function transformESNext(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.

const {
factory,
getEmitHelperFactory: emitHelpers,
Expand Down
62 changes: 62 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7277,6 +7277,9 @@ export const enum ScriptKind {
Deferred = 7,
}

// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
export const enum ScriptTarget {
/** @deprecated */
ES3 = 0,
Expand Down Expand Up @@ -8035,6 +8038,65 @@ export type UniqueNameHandler = (baseName: string, checkFn?: (name: string) => b

export type EmitHelperUniqueNameCallback = (name: string) => string;

/**
* Indicates the minimum `ScriptTarget` (inclusive) after which a specific language feature is no longer transpiled.
*
* @internal
*/
export const enum LanguageFeatureMinimumTarget {
// ES2015 Features
Classes = ScriptTarget.ES2015,
ForOf = ScriptTarget.ES2015,
Generators = ScriptTarget.ES2015,
Iteration = ScriptTarget.ES2015,
SpreadElements = ScriptTarget.ES2015,
RestElements = ScriptTarget.ES2015,
TaggedTemplates = ScriptTarget.ES2015,
DestructuringAssignment = ScriptTarget.ES2015,
BindingPatterns = ScriptTarget.ES2015,
ArrowFunctions = ScriptTarget.ES2015,
BlockScopedVariables = ScriptTarget.ES2015,
ObjectAssign = ScriptTarget.ES2015,

// ES2016 Features
Exponentiation = ScriptTarget.ES2016, // `x ** y`

// ES2017 Features
AsyncFunctions = ScriptTarget.ES2017, // `async function f() {}`

// ES2018 Features
ForAwaitOf = ScriptTarget.ES2018, // `for await (const x of y)`
AsyncGenerators = ScriptTarget.ES2018, // `async function * f() { }`
AsyncIteration = ScriptTarget.ES2018, // `Symbol.asyncIterator`
ObjectSpreadRest = ScriptTarget.ES2018, // `{ ...obj }`

// ES2019 Features
BindinglessCatch = ScriptTarget.ES2019, // `try { } catch { }`

// ES2020 Features
BigInt = ScriptTarget.ES2020, // `0n`
NullishCoalesce = ScriptTarget.ES2020, // `a ?? b`
OptionalChaining = ScriptTarget.ES2020, // `a?.b`

// ES2021 Features
LogicalAssignment = ScriptTarget.ES2021, // `a ||= b`, `a &&= b`, `a ??= b`

// ES2022 Features
TopLevelAwait = ScriptTarget.ES2022,
ClassFields = ScriptTarget.ES2022,
PrivateNamesAndClassStaticBlocks = ScriptTarget.ES2022, // `class C { static {} #x = y, #m() {} }`, `#x in y`

// ES2023 Features
ShebangComments = ScriptTarget.ESNext,

// Upcoming Features
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
UsingAndAwaitUsing = ScriptTarget.ESNext, // `using x = y`, `await using x = y`
ClassAndClassElementDecorators = ScriptTarget.ESNext, // `@dec class C {}`, `class C { @dec m() {} }`
}

// dprint-ignore
/**
* Used by the checker, this enum keeps track of external emit helpers that should be type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ async function f() {
}

//// [awaitUsingDeclarationsWithImportHelpers.js]
import { __addDisposableResource, __disposeResources } from "tslib";
async function f() {
await using a = null;
const env_1 = { stack: [], error: void 0, hasError: false };
try {
const a = __addDisposableResource(env_1, null, true);
}
catch (e_1) {
env_1.error = e_1;
env_1.hasError = true;
}
finally {
const result_1 = __disposeResources(env_1);
if (result_1)
await result_1;
}
}
export {};
14 changes: 12 additions & 2 deletions tests/baselines/reference/usingDeclarationsWithImportHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ export {};
}

//// [usingDeclarationsWithImportHelpers.js]
import { __addDisposableResource, __disposeResources } from "tslib";
{
using a = null;
const env_1 = { stack: [], error: void 0, hasError: false };
try {
const a = __addDisposableResource(env_1, null, false);
}
catch (e_1) {
env_1.error = e_1;
env_1.hasError = true;
}
finally {
__disposeResources(env_1);
}
}
export {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @target: esnext
// @target: es2022
// @module: esnext
// @lib: esnext
// @importHelpers: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @target: esnext
// @target: es2022
// @module: esnext
// @lib: esnext
// @importHelpers: true
Expand Down