Skip to content

Commit 5522627

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/TypeScript into feat/51000
2 parents 7cd82f2 + 4978b3e commit 5522627

File tree

49 files changed

+283
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+283
-254
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10090,8 +10090,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1009010090
// If the parent is a tuple type, the rest element has a tuple type of the
1009110091
// remaining tuple element types. Otherwise, the rest element has an array type with same
1009210092
// element type as the parent type.
10093-
type = everyType(parentType, isTupleType) ?
10094-
mapType(parentType, t => sliceTupleType(t as TupleTypeReference, index)) :
10093+
const baseConstraint = getBaseConstraintOrType(parentType);
10094+
type = everyType(baseConstraint, isTupleType) ?
10095+
mapType(baseConstraint, t => sliceTupleType(t as TupleTypeReference, index)) :
1009510096
createArrayType(elementType);
1009610097
}
1009710098
else if (isArrayLikeType(parentType)) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export const targetOptionDeclaration: CommandLineOptionOfCustomType = {
522522
showInSimplifiedHelpView: true,
523523
category: Diagnostics.Language_and_Environment,
524524
description: Diagnostics.Set_the_JavaScript_language_version_for_emitted_JavaScript_and_include_compatible_library_declarations,
525-
defaultValueDescription: ScriptTarget.ES3,
525+
defaultValueDescription: ScriptTarget.ES5,
526526
};
527527

528528
/** @internal */

src/compiler/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7515,10 +7515,10 @@ export function getSetExternalModuleIndicator(options: CompilerOptions): (file:
75157515

75167516
/** @internal */
75177517
export function getEmitScriptTarget(compilerOptions: {module?: CompilerOptions["module"], target?: CompilerOptions["target"]}): ScriptTarget {
7518-
return compilerOptions.target ||
7519-
(compilerOptions.module === ModuleKind.Node16 && ScriptTarget.ES2022) ||
7518+
return compilerOptions.target ??
7519+
((compilerOptions.module === ModuleKind.Node16 && ScriptTarget.ES2022) ||
75207520
(compilerOptions.module === ModuleKind.NodeNext && ScriptTarget.ESNext) ||
7521-
ScriptTarget.ES5;
7521+
ScriptTarget.ES5);
75227522
}
75237523

75247524
/** @internal */

src/services/completions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,9 @@ function createCompletionEntry(
13921392
sortText = SortText.SortBelow(sortText);
13931393
}
13941394

1395-
if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
1395+
if (isJsxIdentifierExpected && !isRightOfOpenTag
1396+
&& preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle
1397+
&& preferences.jsxAttributeCompletionStyle !== "none" && !(isJsxAttribute(location.parent) && location.parent.initializer)) {
13961398
let useBraces = preferences.jsxAttributeCompletionStyle === "braces";
13971399
const type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
13981400

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts(1,15): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts (1 errors) ====
5+
for (var v of "") { }
6+
~~
7+
!!! error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts(2,17): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts (1 errors) ====
5+
var union: string | string[];
6+
for (const v of union) { }
7+
~~~~~
8+
!!! error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(10,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
4+
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5+
6+
7+
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts (4 errors) ====
8+
// error to use accessors in ES3 mode
9+
10+
class C {
11+
get x() {
12+
~
13+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
14+
return 1;
15+
}
16+
}
17+
18+
class D {
19+
set x(v) {
20+
~
21+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
22+
}
23+
}
24+
25+
var x = {
26+
get a() { return 1 }
27+
~
28+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
29+
}
30+
31+
var y = {
32+
set b(v) { }
33+
~
34+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/accessorsNotAllowedInES3.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2+
tests/cases/compiler/accessorsNotAllowedInES3.ts(4,15): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3+
4+
5+
==== tests/cases/compiler/accessorsNotAllowedInES3.ts (2 errors) ====
6+
class C {
7+
get x(): number { return 1; }
8+
~
9+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
10+
}
11+
var y = { get foo() { return 3; } };
12+
~~~
13+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error TS5048: Option 'useDefineForClassFields' cannot be specified when option 'target' is 'ES3'.
2+
3+
4+
!!! error TS5048: Option 'useDefineForClassFields' cannot be specified when option 'target' is 'ES3'.
5+
==== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts (0 errors) ====
6+
class A {
7+
a = 12
8+
}
9+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
tests/cases/compiler/es3-oldStyleOctalLiteralInEnums.ts(2,7): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o1'.
2-
tests/cases/compiler/es3-oldStyleOctalLiteralInEnums.ts(3,7): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o2'.
1+
tests/cases/compiler/es3-oldStyleOctalLiteralInEnums.ts(2,7): error TS8018: Octal literals are not allowed in enums members initializer. Use the syntax '-0o1'.
2+
tests/cases/compiler/es3-oldStyleOctalLiteralInEnums.ts(3,7): error TS8018: Octal literals are not allowed in enums members initializer. Use the syntax '0o2'.
33

44

55
==== tests/cases/compiler/es3-oldStyleOctalLiteralInEnums.ts (2 errors) ====
66
enum E {
77
x = -01,
88
~~~
9-
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o1'.
9+
!!! error TS8018: Octal literals are not allowed in enums members initializer. Use the syntax '-0o1'.
1010
y = 02,
1111
~~
12-
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o2'.
12+
!!! error TS8018: Octal literals are not allowed in enums members initializer. Use the syntax '0o2'.
1313
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/compiler/es3-oldStyleOctalLiteralTypes.ts(1,8): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o10'.
2-
tests/cases/compiler/es3-oldStyleOctalLiteralTypes.ts(2,8): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o20'.
1+
tests/cases/compiler/es3-oldStyleOctalLiteralTypes.ts(1,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
2+
tests/cases/compiler/es3-oldStyleOctalLiteralTypes.ts(2,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '-0o20'.
33

44

55
==== tests/cases/compiler/es3-oldStyleOctalLiteralTypes.ts (2 errors) ====
66
let x: 010;
77
~~~
8-
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o10'.
8+
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'.
99
let y: -020;
1010
~~~~
11-
!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '-0o20'.
11+
!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '-0o20'.
1212

tests/baselines/reference/es3defaultAliasIsQuoted.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ assert(Foo.CONSTANT === "Foo");
1515

1616
//// [es3defaultAliasQuoted_file0.js]
1717
"use strict";
18-
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.__esModule = true;
1919
exports.Foo = void 0;
2020
var Foo = /** @class */ (function () {
2121
function Foo() {
@@ -28,9 +28,9 @@ function assert(value) {
2828
if (!value)
2929
throw new Error("Assertion failed!");
3030
}
31-
exports.default = assert;
31+
exports["default"] = assert;
3232
//// [es3defaultAliasQuoted_file1.js]
3333
"use strict";
34-
Object.defineProperty(exports, "__esModule", { value: true });
34+
exports.__esModule = true;
3535
var es3defaultAliasQuoted_file0_1 = require("./es3defaultAliasQuoted_file0");
36-
(0, es3defaultAliasQuoted_file0_1.default)(es3defaultAliasQuoted_file0_1.Foo.CONSTANT === "Foo");
36+
(0, es3defaultAliasQuoted_file0_1["default"])(es3defaultAliasQuoted_file0_1.Foo.CONSTANT === "Foo");

tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
4040
var __exportStar = (this && this.__exportStar) || function(m, exports) {
4141
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4242
};
43-
Object.defineProperty(exports, "__esModule", { value: true });
43+
exports.__esModule = true;
4444
exports.y = exports.x = void 0;
4545
var fs = __importStar(require("./fs"));
4646
fs;
4747
__exportStar(require("./fs"), exports);
4848
var fs_1 = require("./fs");
49-
Object.defineProperty(exports, "x", { enumerable: true, get: function () { return fs_1.x; } });
49+
__createBinding(exports, fs_1, "x");
5050
var fs_2 = require("./fs");
51-
Object.defineProperty(exports, "y", { enumerable: true, get: function () { return fs_2.x; } });
51+
__createBinding(exports, fs_2, "x", "y");

tests/baselines/reference/exportAndImport-es3-amd.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export default function f2() {
1414
//// [m1.js]
1515
define(["require", "exports"], function (require, exports) {
1616
"use strict";
17-
Object.defineProperty(exports, "__esModule", { value: true });
17+
exports.__esModule = true;
1818
function f1() {
1919
}
20-
exports.default = f1;
20+
exports["default"] = f1;
2121
});
2222
//// [m2.js]
2323
define(["require", "exports", "./m1"], function (require, exports, m1_1) {
2424
"use strict";
25-
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.__esModule = true;
2626
function f2() {
27-
(0, m1_1.default)();
27+
(0, m1_1["default"])();
2828
}
29-
exports.default = f2;
29+
exports["default"] = f2;
3030
});

tests/baselines/reference/exportAndImport-es3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export default function f2() {
1313

1414
//// [m1.js]
1515
"use strict";
16-
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.__esModule = true;
1717
function f1() {
1818
}
19-
exports.default = f1;
19+
exports["default"] = f1;
2020
//// [m2.js]
2121
"use strict";
22-
Object.defineProperty(exports, "__esModule", { value: true });
22+
exports.__esModule = true;
2323
var m1_1 = require("./m1");
2424
function f2() {
25-
(0, m1_1.default)();
25+
(0, m1_1["default"])();
2626
}
27-
exports.default = f2;
27+
exports["default"] = f2;

tests/baselines/reference/exportsAndImportsWithUnderscores1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const { __, _, ___ } = R;
1515

1616
//// [m1.js]
1717
"use strict";
18-
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.__esModule = true;
1919
var R;
20-
exports.default = R = {
20+
exports["default"] = R = {
2121
"__": 20,
2222
"_": 10,
2323
"___": 30
2424
};
2525
//// [m2.js]
2626
"use strict";
27-
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.__esModule = true;
2828
var m1_1 = require("./m1");
29-
var __ = m1_1.default.__, _ = m1_1.default._, ___ = m1_1.default.___;
29+
var __ = m1_1["default"].__, _ = m1_1["default"]._, ___ = m1_1["default"].___;

tests/baselines/reference/exportsAndImportsWithUnderscores2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const { __esmodule, __proto__ } = R;
1414

1515
//// [m1.js]
1616
"use strict";
17-
Object.defineProperty(exports, "__esModule", { value: true });
17+
exports.__esModule = true;
1818
var R;
19-
exports.default = R = {
19+
exports["default"] = R = {
2020
"__esmodule": true,
2121
"__proto__": {}
2222
};
2323
//// [m2.js]
2424
"use strict";
25-
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.__esModule = true;
2626
var m1_1 = require("./m1");
27-
var __esmodule = m1_1.default.__esmodule, __proto__ = m1_1.default.__proto__;
27+
var __esmodule = m1_1["default"].__esmodule, __proto__ = m1_1["default"].__proto__;

tests/baselines/reference/exportsAndImportsWithUnderscores3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const { ___, ___hello, _hi } = R;
1515

1616
//// [m1.js]
1717
"use strict";
18-
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.__esModule = true;
1919
var R;
20-
exports.default = R = {
20+
exports["default"] = R = {
2121
"___": 30,
2222
"___hello": 21,
23-
"_hi": 40,
23+
"_hi": 40
2424
};
2525
//// [m2.js]
2626
"use strict";
27-
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.__esModule = true;
2828
var m1_1 = require("./m1");
29-
var ___ = m1_1.default.___, ___hello = m1_1.default.___hello, _hi = m1_1.default._hi;
29+
var ___ = m1_1["default"].___, ___hello = m1_1["default"].___hello, _hi = m1_1["default"]._hi;

tests/baselines/reference/exportsAndImportsWithUnderscores4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _hi();
3535

3636
//// [m1.js]
3737
"use strict";
38-
Object.defineProperty(exports, "__esModule", { value: true });
38+
exports.__esModule = true;
3939
exports.___hello = exports.__esmodule = exports.__proto = exports._hi = exports.___ = exports.__ = exports._ = void 0;
4040
function _() {
4141
console.log("_");
@@ -67,7 +67,7 @@ function ___hello() {
6767
exports.___hello = ___hello;
6868
//// [m2.js]
6969
"use strict";
70-
Object.defineProperty(exports, "__esModule", { value: true });
70+
exports.__esModule = true;
7171
var m1_1 = require("./m1");
7272
(0, m1_1._)();
7373
(0, m1_1.__)();

tests/baselines/reference/importCallExpressionAsyncES3AMD.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
6767
};
6868
define(["require", "exports"], function (require, exports) {
6969
"use strict";
70-
Object.defineProperty(exports, "__esModule", { value: true });
70+
exports.__esModule = true;
7171
exports.l = exports.cl2 = exports.obj = exports.cl1 = exports.fn = void 0;
7272
function fn() {
7373
return __awaiter(this, void 0, void 0, function () {

tests/baselines/reference/importCallExpressionAsyncES3CJS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
6666
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6767
}
6868
};
69-
Object.defineProperty(exports, "__esModule", { value: true });
69+
exports.__esModule = true;
7070
exports.l = exports.cl2 = exports.obj = exports.cl1 = exports.fn = void 0;
7171
function fn() {
7272
return __awaiter(this, void 0, void 0, function () {

tests/baselines/reference/importCallExpressionAsyncES3System.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ System.register([], function (exports_1, context_1) {
7474
var req;
7575
return __generator(this, function (_a) {
7676
switch (_a.label) {
77-
case 0: return [4 /*yield*/, context_1.import('./test')]; // ONE
77+
case 0: return [4 /*yield*/, context_1["import"]('./test')]; // ONE
7878
case 1:
7979
req = _a.sent() // ONE
8080
;
@@ -95,7 +95,7 @@ System.register([], function (exports_1, context_1) {
9595
var req;
9696
return __generator(this, function (_a) {
9797
switch (_a.label) {
98-
case 0: return [4 /*yield*/, context_1.import('./test')]; // TWO
98+
case 0: return [4 /*yield*/, context_1["import"]('./test')]; // TWO
9999
case 1:
100100
req = _a.sent() // TWO
101101
;
@@ -112,7 +112,7 @@ System.register([], function (exports_1, context_1) {
112112
var req;
113113
return __generator(this, function (_a) {
114114
switch (_a.label) {
115-
case 0: return [4 /*yield*/, context_1.import('./test')]; // THREE
115+
case 0: return [4 /*yield*/, context_1["import"]('./test')]; // THREE
116116
case 1:
117117
req = _a.sent() // THREE
118118
;
@@ -129,7 +129,7 @@ System.register([], function (exports_1, context_1) {
129129
var req;
130130
return __generator(this, function (_a) {
131131
switch (_a.label) {
132-
case 0: return [4 /*yield*/, context_1.import('./test')]; // FOUR
132+
case 0: return [4 /*yield*/, context_1["import"]('./test')]; // FOUR
133133
case 1:
134134
req = _a.sent() // FOUR
135135
;
@@ -146,7 +146,7 @@ System.register([], function (exports_1, context_1) {
146146
var req;
147147
return __generator(this, function (_a) {
148148
switch (_a.label) {
149-
case 0: return [4 /*yield*/, context_1.import('./test')]; // FIVE
149+
case 0: return [4 /*yield*/, context_1["import"]('./test')]; // FIVE
150150
case 1:
151151
req = _a.sent() // FIVE
152152
;

tests/baselines/reference/importCallExpressionAsyncES3UMD.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
7676
})(function (require, exports) {
7777
"use strict";
7878
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
79-
Object.defineProperty(exports, "__esModule", { value: true });
79+
exports.__esModule = true;
8080
exports.l = exports.cl2 = exports.obj = exports.cl1 = exports.fn = void 0;
8181
function fn() {
8282
return __awaiter(this, void 0, void 0, function () {

0 commit comments

Comments
 (0)