typescript 5.5.0-dev.20240423 → 5.5.0-dev.20240425
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsc.js +129 -46
- package/lib/typescript.d.ts +1 -0
- package/lib/typescript.js +193 -53
- package/package.json +2 -2
package/lib/tsc.js
CHANGED
|
@@ -18,7 +18,7 @@ and limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
// src/compiler/corePublic.ts
|
|
20
20
|
var versionMajorMinor = "5.5";
|
|
21
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
21
|
+
var version = `${versionMajorMinor}.0-dev.20240425`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -6206,8 +6206,8 @@ var Diagnostics = {
|
|
|
6206
6206
|
Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set: diag(1530, 1 /* Error */, "Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v__1530", "Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set."),
|
|
6207
6207
|
_0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces: diag(1531, 1 /* Error */, "_0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces_1531", "'\\{0}' must be followed by a Unicode property value expression enclosed in braces."),
|
|
6208
6208
|
There_is_no_capturing_group_named_0_in_this_regular_expression: diag(1532, 1 /* Error */, "There_is_no_capturing_group_named_0_in_this_regular_expression_1532", "There is no capturing group named '{0}' in this regular expression."),
|
|
6209
|
-
|
|
6210
|
-
|
|
6209
|
+
This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression: diag(1533, 1 /* Error */, "This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_r_1533", "This backreference refers to a group that does not exist. There are only {0} capturing groups in this regular expression."),
|
|
6210
|
+
This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups: diag(1534, 1 /* Error */, "This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups_1534", "This backreference is invalid because the containing regular expression contains no capturing groups."),
|
|
6211
6211
|
This_character_cannot_be_escaped_in_a_regular_expression: diag(1535, 1 /* Error */, "This_character_cannot_be_escaped_in_a_regular_expression_1535", "This character cannot be escaped in a regular expression."),
|
|
6212
6212
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, 1 /* Error */, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
6213
6213
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, 1 /* Error */, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
@@ -9012,7 +9012,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9012
9012
|
tokenFlags |= 2048 /* ContainsInvalidEscape */;
|
|
9013
9013
|
if (isRegularExpression || shouldEmitInvalidEscapeError) {
|
|
9014
9014
|
const code = parseInt(text.substring(start2 + 1, pos), 8);
|
|
9015
|
-
|
|
9015
|
+
if (isRegularExpression !== "annex-b") {
|
|
9016
|
+
error(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start2, pos - start2, "\\x" + code.toString(16).padStart(2, "0"));
|
|
9017
|
+
}
|
|
9016
9018
|
return String.fromCharCode(code);
|
|
9017
9019
|
}
|
|
9018
9020
|
return text.substring(start2, pos);
|
|
@@ -9043,7 +9045,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9043
9045
|
case 117 /* u */:
|
|
9044
9046
|
if ((!isRegularExpression || shouldEmitInvalidEscapeError) && pos < end && text.charCodeAt(pos) === 123 /* openBrace */) {
|
|
9045
9047
|
pos -= 2;
|
|
9046
|
-
return scanExtendedUnicodeEscape(isRegularExpression || shouldEmitInvalidEscapeError);
|
|
9048
|
+
return scanExtendedUnicodeEscape(!!isRegularExpression || shouldEmitInvalidEscapeError);
|
|
9047
9049
|
}
|
|
9048
9050
|
for (; pos < start2 + 6; pos++) {
|
|
9049
9051
|
if (!(pos < end && isHexDigit(text.charCodeAt(pos)))) {
|
|
@@ -9093,7 +9095,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9093
9095
|
case 8233 /* paragraphSeparator */:
|
|
9094
9096
|
return "";
|
|
9095
9097
|
default:
|
|
9096
|
-
if (isRegularExpression && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
|
|
9098
|
+
if (isRegularExpression === true && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
|
|
9097
9099
|
error(Diagnostics.This_character_cannot_be_escaped_in_a_regular_expression, pos - 2, 2);
|
|
9098
9100
|
}
|
|
9099
9101
|
return String.fromCharCode(ch);
|
|
@@ -9788,7 +9790,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9788
9790
|
pos = tokenStart + 1;
|
|
9789
9791
|
return token = 64 /* EqualsToken */;
|
|
9790
9792
|
}
|
|
9791
|
-
function reScanSlashToken() {
|
|
9793
|
+
function reScanSlashToken(reportErrors2) {
|
|
9792
9794
|
if (token === 44 /* SlashToken */ || token === 69 /* SlashEqualsToken */) {
|
|
9793
9795
|
let p = tokenStart + 1;
|
|
9794
9796
|
let inEscape = false;
|
|
@@ -9827,38 +9829,54 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9827
9829
|
if (!isIdentifierPart(ch, languageVersion)) {
|
|
9828
9830
|
break;
|
|
9829
9831
|
}
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9832
|
+
if (reportErrors2) {
|
|
9833
|
+
const flag = characterToRegularExpressionFlag(String.fromCharCode(ch));
|
|
9834
|
+
if (flag === void 0) {
|
|
9835
|
+
error(Diagnostics.Unknown_regular_expression_flag, p, 1);
|
|
9836
|
+
} else if (regExpFlags & flag) {
|
|
9837
|
+
error(Diagnostics.Duplicate_regular_expression_flag, p, 1);
|
|
9838
|
+
} else if (((regExpFlags | flag) & 96 /* UnicodeMode */) === 96 /* UnicodeMode */) {
|
|
9839
|
+
error(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1);
|
|
9840
|
+
} else {
|
|
9841
|
+
regExpFlags |= flag;
|
|
9842
|
+
const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
|
|
9843
|
+
if (languageVersion < availableFrom) {
|
|
9844
|
+
error(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, p, 1, getNameOfScriptTarget(availableFrom));
|
|
9845
|
+
}
|
|
9842
9846
|
}
|
|
9843
9847
|
}
|
|
9844
9848
|
p++;
|
|
9845
9849
|
}
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9850
|
+
if (reportErrors2) {
|
|
9851
|
+
pos = tokenStart + 1;
|
|
9852
|
+
const saveTokenPos = tokenStart;
|
|
9853
|
+
const saveTokenFlags = tokenFlags;
|
|
9854
|
+
scanRegularExpressionWorker(
|
|
9855
|
+
text,
|
|
9856
|
+
endOfBody,
|
|
9857
|
+
regExpFlags,
|
|
9858
|
+
isUnterminated,
|
|
9859
|
+
/*annexB*/
|
|
9860
|
+
true
|
|
9861
|
+
);
|
|
9862
|
+
if (!isUnterminated) {
|
|
9863
|
+
pos = p;
|
|
9864
|
+
}
|
|
9865
|
+
tokenStart = saveTokenPos;
|
|
9866
|
+
tokenFlags = saveTokenFlags;
|
|
9867
|
+
} else {
|
|
9851
9868
|
pos = p;
|
|
9852
9869
|
}
|
|
9853
|
-
tokenStart = saveTokenPos;
|
|
9854
|
-
tokenFlags = saveTokenFlags;
|
|
9855
9870
|
tokenValue = text.substring(tokenStart, pos);
|
|
9856
9871
|
token = 14 /* RegularExpressionLiteral */;
|
|
9857
9872
|
}
|
|
9858
9873
|
return token;
|
|
9859
|
-
function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated) {
|
|
9860
|
-
const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
|
|
9874
|
+
function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated, annexB) {
|
|
9861
9875
|
const unicodeSetsMode = !!(regExpFlags & 64 /* UnicodeSets */);
|
|
9876
|
+
const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
|
|
9877
|
+
if (unicodeMode) {
|
|
9878
|
+
annexB = false;
|
|
9879
|
+
}
|
|
9862
9880
|
let mayContainStrings = false;
|
|
9863
9881
|
let numberOfCapturingGroups = 0;
|
|
9864
9882
|
const groupSpecifiers = /* @__PURE__ */ new Set();
|
|
@@ -9909,7 +9927,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
9909
9927
|
case 61 /* equals */:
|
|
9910
9928
|
case 33 /* exclamation */:
|
|
9911
9929
|
pos++;
|
|
9912
|
-
isPreviousTermQuantifiable =
|
|
9930
|
+
isPreviousTermQuantifiable = annexB;
|
|
9913
9931
|
break;
|
|
9914
9932
|
case 60 /* lessThan */:
|
|
9915
9933
|
const groupNameStart = pos;
|
|
@@ -10088,7 +10106,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10088
10106
|
break;
|
|
10089
10107
|
}
|
|
10090
10108
|
default:
|
|
10091
|
-
Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(
|
|
10109
|
+
Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(
|
|
10110
|
+
/*atomEscape*/
|
|
10111
|
+
true
|
|
10112
|
+
));
|
|
10092
10113
|
break;
|
|
10093
10114
|
}
|
|
10094
10115
|
}
|
|
@@ -10103,7 +10124,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10103
10124
|
}
|
|
10104
10125
|
return false;
|
|
10105
10126
|
}
|
|
10106
|
-
function scanCharacterEscape() {
|
|
10127
|
+
function scanCharacterEscape(atomEscape) {
|
|
10107
10128
|
Debug.assertEqual(text2.charCodeAt(pos - 1), 92 /* backslash */);
|
|
10108
10129
|
let ch = text2.charCodeAt(pos);
|
|
10109
10130
|
switch (ch) {
|
|
@@ -10116,6 +10137,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10116
10137
|
}
|
|
10117
10138
|
if (unicodeMode) {
|
|
10118
10139
|
error(Diagnostics.c_must_be_followed_by_an_ASCII_letter, pos - 2, 2);
|
|
10140
|
+
} else if (atomEscape && annexB) {
|
|
10141
|
+
pos--;
|
|
10142
|
+
return "\\";
|
|
10119
10143
|
}
|
|
10120
10144
|
return String.fromCharCode(ch);
|
|
10121
10145
|
case 94 /* caret */:
|
|
@@ -10145,7 +10169,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10145
10169
|
/*shouldEmitInvalidEscapeError*/
|
|
10146
10170
|
unicodeMode,
|
|
10147
10171
|
/*isRegularExpression*/
|
|
10148
|
-
true
|
|
10172
|
+
annexB ? "annex-b" : true
|
|
10149
10173
|
);
|
|
10150
10174
|
}
|
|
10151
10175
|
}
|
|
@@ -10185,12 +10209,12 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10185
10209
|
if (isClassContentExit(ch2)) {
|
|
10186
10210
|
return;
|
|
10187
10211
|
}
|
|
10188
|
-
if (!minCharacter) {
|
|
10212
|
+
if (!minCharacter && !annexB) {
|
|
10189
10213
|
error(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, minStart, pos - 1 - minStart);
|
|
10190
10214
|
}
|
|
10191
10215
|
const maxStart = pos;
|
|
10192
10216
|
const maxCharacter = scanClassAtom();
|
|
10193
|
-
if (!maxCharacter) {
|
|
10217
|
+
if (!maxCharacter && !annexB) {
|
|
10194
10218
|
error(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, maxStart, pos - maxStart);
|
|
10195
10219
|
continue;
|
|
10196
10220
|
}
|
|
@@ -10473,7 +10497,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10473
10497
|
pos++;
|
|
10474
10498
|
return String.fromCharCode(ch2);
|
|
10475
10499
|
default:
|
|
10476
|
-
return scanCharacterEscape(
|
|
10500
|
+
return scanCharacterEscape(
|
|
10501
|
+
/*atomEscape*/
|
|
10502
|
+
false
|
|
10503
|
+
);
|
|
10477
10504
|
}
|
|
10478
10505
|
} else if (ch === text2.charCodeAt(pos + 1)) {
|
|
10479
10506
|
switch (ch) {
|
|
@@ -10530,7 +10557,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10530
10557
|
if (scanCharacterClassEscape()) {
|
|
10531
10558
|
return "";
|
|
10532
10559
|
}
|
|
10533
|
-
return scanCharacterEscape(
|
|
10560
|
+
return scanCharacterEscape(
|
|
10561
|
+
/*atomEscape*/
|
|
10562
|
+
false
|
|
10563
|
+
);
|
|
10534
10564
|
}
|
|
10535
10565
|
} else {
|
|
10536
10566
|
return scanSourceCharacter();
|
|
@@ -10645,11 +10675,11 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
10645
10675
|
}
|
|
10646
10676
|
});
|
|
10647
10677
|
forEach(decimalEscapes, (escape) => {
|
|
10648
|
-
if (escape.value > numberOfCapturingGroups) {
|
|
10678
|
+
if (!annexB && escape.value > numberOfCapturingGroups) {
|
|
10649
10679
|
if (numberOfCapturingGroups) {
|
|
10650
|
-
error(Diagnostics.
|
|
10680
|
+
error(Diagnostics.This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression, escape.pos, escape.end - escape.pos, numberOfCapturingGroups);
|
|
10651
10681
|
} else {
|
|
10652
|
-
error(Diagnostics.
|
|
10682
|
+
error(Diagnostics.This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups, escape.pos, escape.end - escape.pos);
|
|
10653
10683
|
}
|
|
10654
10684
|
}
|
|
10655
10685
|
});
|
|
@@ -45252,6 +45282,7 @@ function createTypeChecker(host) {
|
|
|
45252
45282
|
var requestedExternalEmitHelperNames = /* @__PURE__ */ new Set();
|
|
45253
45283
|
var requestedExternalEmitHelpers;
|
|
45254
45284
|
var externalHelpersModule;
|
|
45285
|
+
var scanner;
|
|
45255
45286
|
var Symbol12 = objectAllocator.getSymbolConstructor();
|
|
45256
45287
|
var Type7 = objectAllocator.getTypeConstructor();
|
|
45257
45288
|
var Signature5 = objectAllocator.getSignatureConstructor();
|
|
@@ -50111,7 +50142,8 @@ function createTypeChecker(host) {
|
|
|
50111
50142
|
deepCloneOrReuseNode,
|
|
50112
50143
|
/*context*/
|
|
50113
50144
|
void 0,
|
|
50114
|
-
deepCloneOrReuseNodes
|
|
50145
|
+
deepCloneOrReuseNodes,
|
|
50146
|
+
deepCloneOrReuseNode
|
|
50115
50147
|
)), node);
|
|
50116
50148
|
}
|
|
50117
50149
|
function deepCloneOrReuseNodes(nodes, visitor, test, start, count) {
|
|
@@ -71090,6 +71122,53 @@ function createTypeChecker(host) {
|
|
|
71090
71122
|
return signatureList.length === 1 ? signatureList[0] : createUnionSignature(signatureList[0], signatureList);
|
|
71091
71123
|
}
|
|
71092
71124
|
}
|
|
71125
|
+
function checkGrammarRegularExpressionLiteral(node) {
|
|
71126
|
+
const sourceFile = getSourceFileOfNode(node);
|
|
71127
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
71128
|
+
let lastError;
|
|
71129
|
+
scanner ?? (scanner = createScanner(
|
|
71130
|
+
99 /* ESNext */,
|
|
71131
|
+
/*skipTrivia*/
|
|
71132
|
+
true
|
|
71133
|
+
));
|
|
71134
|
+
scanner.setScriptTarget(sourceFile.languageVersion);
|
|
71135
|
+
scanner.setLanguageVariant(sourceFile.languageVariant);
|
|
71136
|
+
scanner.setOnError((message, length2, arg0) => {
|
|
71137
|
+
const start = scanner.getTokenEnd();
|
|
71138
|
+
if (message.category === 3 /* Message */ && lastError && start === lastError.start && length2 === lastError.length) {
|
|
71139
|
+
const error2 = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length2, message, arg0);
|
|
71140
|
+
addRelatedInfo(lastError, error2);
|
|
71141
|
+
} else if (!lastError || start !== lastError.start) {
|
|
71142
|
+
lastError = createFileDiagnostic(sourceFile, start, length2, message, arg0);
|
|
71143
|
+
diagnostics.add(lastError);
|
|
71144
|
+
}
|
|
71145
|
+
});
|
|
71146
|
+
scanner.setText(sourceFile.text, node.pos, node.end - node.pos);
|
|
71147
|
+
try {
|
|
71148
|
+
scanner.scan();
|
|
71149
|
+
Debug.assert(scanner.reScanSlashToken(
|
|
71150
|
+
/*reportErrors*/
|
|
71151
|
+
true
|
|
71152
|
+
) === 14 /* RegularExpressionLiteral */, "Expected scanner to rescan RegularExpressionLiteral");
|
|
71153
|
+
return !!lastError;
|
|
71154
|
+
} finally {
|
|
71155
|
+
scanner.setText("");
|
|
71156
|
+
scanner.setOnError(
|
|
71157
|
+
/*onError*/
|
|
71158
|
+
void 0
|
|
71159
|
+
);
|
|
71160
|
+
}
|
|
71161
|
+
}
|
|
71162
|
+
return false;
|
|
71163
|
+
}
|
|
71164
|
+
function checkRegularExpressionLiteral(node) {
|
|
71165
|
+
const nodeLinks2 = getNodeLinks(node);
|
|
71166
|
+
if (!(nodeLinks2.flags & 1 /* TypeChecked */)) {
|
|
71167
|
+
nodeLinks2.flags |= 1 /* TypeChecked */;
|
|
71168
|
+
addLazyDiagnostic(() => checkGrammarRegularExpressionLiteral(node));
|
|
71169
|
+
}
|
|
71170
|
+
return globalRegExpType;
|
|
71171
|
+
}
|
|
71093
71172
|
function checkSpreadExpression(node, checkMode) {
|
|
71094
71173
|
if (languageVersion < 2 /* SpreadElements */) {
|
|
71095
71174
|
checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? 1536 /* SpreadIncludes */ : 1024 /* SpreadArray */);
|
|
@@ -76993,7 +77072,7 @@ function createTypeChecker(host) {
|
|
|
76993
77072
|
parent = parent.parent;
|
|
76994
77073
|
}
|
|
76995
77074
|
if (operator === 56 /* AmpersandAmpersandToken */ || isIfStatement(parent)) {
|
|
76996
|
-
|
|
77075
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent) ? parent.thenStatement : void 0);
|
|
76997
77076
|
}
|
|
76998
77077
|
checkTruthinessOfType(leftType, node.left);
|
|
76999
77078
|
}
|
|
@@ -77551,7 +77630,7 @@ function createTypeChecker(host) {
|
|
|
77551
77630
|
}
|
|
77552
77631
|
function checkConditionalExpression(node, checkMode) {
|
|
77553
77632
|
const type = checkTruthinessExpression(node.condition, checkMode);
|
|
77554
|
-
|
|
77633
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.condition, type, node.whenTrue);
|
|
77555
77634
|
const type1 = checkExpression(node.whenTrue, checkMode);
|
|
77556
77635
|
const type2 = checkExpression(node.whenFalse, checkMode);
|
|
77557
77636
|
return getUnionType([type1, type2], 2 /* Subtype */);
|
|
@@ -78024,7 +78103,7 @@ function createTypeChecker(host) {
|
|
|
78024
78103
|
case 228 /* TemplateExpression */:
|
|
78025
78104
|
return checkTemplateExpression(node);
|
|
78026
78105
|
case 14 /* RegularExpressionLiteral */:
|
|
78027
|
-
return
|
|
78106
|
+
return checkRegularExpressionLiteral(node);
|
|
78028
78107
|
case 209 /* ArrayLiteralExpression */:
|
|
78029
78108
|
return checkArrayLiteral(node, checkMode, forceTuple);
|
|
78030
78109
|
case 210 /* ObjectLiteralExpression */:
|
|
@@ -80599,14 +80678,14 @@ function createTypeChecker(host) {
|
|
|
80599
80678
|
function checkIfStatement(node) {
|
|
80600
80679
|
checkGrammarStatementInAmbientContext(node);
|
|
80601
80680
|
const type = checkTruthinessExpression(node.expression);
|
|
80602
|
-
|
|
80681
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.expression, type, node.thenStatement);
|
|
80603
80682
|
checkSourceElement(node.thenStatement);
|
|
80604
80683
|
if (node.thenStatement.kind === 242 /* EmptyStatement */) {
|
|
80605
80684
|
error(node.thenStatement, Diagnostics.The_body_of_an_if_statement_cannot_be_the_empty_statement);
|
|
80606
80685
|
}
|
|
80607
80686
|
checkSourceElement(node.elseStatement);
|
|
80608
80687
|
}
|
|
80609
|
-
function
|
|
80688
|
+
function checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(condExpr, condType, body) {
|
|
80610
80689
|
if (!strictNullChecks)
|
|
80611
80690
|
return;
|
|
80612
80691
|
bothHelper(condExpr, body);
|
|
@@ -80628,6 +80707,10 @@ function createTypeChecker(host) {
|
|
|
80628
80707
|
return;
|
|
80629
80708
|
}
|
|
80630
80709
|
const type = location === condExpr2 ? condType : checkTruthinessExpression(location);
|
|
80710
|
+
if (type.flags & 1024 /* EnumLiteral */ && isPropertyAccessExpression(location) && (getNodeLinks(location.expression).resolvedSymbol ?? unknownSymbol).flags & 384 /* Enum */) {
|
|
80711
|
+
error(location, Diagnostics.This_condition_will_always_return_0, !!type.value ? "true" : "false");
|
|
80712
|
+
return;
|
|
80713
|
+
}
|
|
80631
80714
|
const isPropertyExpressionCast = isPropertyAccessExpression(location) && isTypeAssertion(location.expression);
|
|
80632
80715
|
if (!hasTypeFacts(type, 4194304 /* Truthy */) || isPropertyExpressionCast)
|
|
80633
80716
|
return;
|
|
@@ -83073,7 +83156,7 @@ function createTypeChecker(host) {
|
|
|
83073
83156
|
if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
|
|
83074
83157
|
return;
|
|
83075
83158
|
}
|
|
83076
|
-
if (!checkGrammarModifiers(node) &&
|
|
83159
|
+
if (!checkGrammarModifiers(node) && node.modifiers) {
|
|
83077
83160
|
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
|
|
83078
83161
|
}
|
|
83079
83162
|
if (checkExternalImportOrExportDeclaration(node)) {
|
package/lib/typescript.d.ts
CHANGED
|
@@ -11190,6 +11190,7 @@ declare namespace ts {
|
|
|
11190
11190
|
};
|
|
11191
11191
|
function preProcessFile(sourceText: string, readImportFiles?: boolean, detectJavaScriptImports?: boolean): PreProcessedFileInfo;
|
|
11192
11192
|
function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
|
11193
|
+
function transpileDeclaration(input: string, transpileOptions: TranspileOptions): TranspileOutput;
|
|
11193
11194
|
function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string;
|
|
11194
11195
|
interface TranspileOptions {
|
|
11195
11196
|
compilerOptions?: CompilerOptions;
|
package/lib/typescript.js
CHANGED
|
@@ -2272,6 +2272,7 @@ __export(typescript_exports, {
|
|
|
2272
2272
|
transformSystemModule: () => transformSystemModule,
|
|
2273
2273
|
transformTypeScript: () => transformTypeScript,
|
|
2274
2274
|
transpile: () => transpile,
|
|
2275
|
+
transpileDeclaration: () => transpileDeclaration,
|
|
2275
2276
|
transpileModule: () => transpileModule,
|
|
2276
2277
|
transpileOptionValueCompilerOptions: () => transpileOptionValueCompilerOptions,
|
|
2277
2278
|
tryAddToSet: () => tryAddToSet,
|
|
@@ -2360,7 +2361,7 @@ module.exports = __toCommonJS(typescript_exports);
|
|
|
2360
2361
|
|
|
2361
2362
|
// src/compiler/corePublic.ts
|
|
2362
2363
|
var versionMajorMinor = "5.5";
|
|
2363
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
2364
|
+
var version = `${versionMajorMinor}.0-dev.20240425`;
|
|
2364
2365
|
var Comparison = /* @__PURE__ */ ((Comparison3) => {
|
|
2365
2366
|
Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
|
|
2366
2367
|
Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
|
|
@@ -9812,8 +9813,8 @@ var Diagnostics = {
|
|
|
9812
9813
|
Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set: diag(1530, 1 /* Error */, "Unicode_property_value_expressions_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v__1530", "Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set."),
|
|
9813
9814
|
_0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces: diag(1531, 1 /* Error */, "_0_must_be_followed_by_a_Unicode_property_value_expression_enclosed_in_braces_1531", "'\\{0}' must be followed by a Unicode property value expression enclosed in braces."),
|
|
9814
9815
|
There_is_no_capturing_group_named_0_in_this_regular_expression: diag(1532, 1 /* Error */, "There_is_no_capturing_group_named_0_in_this_regular_expression_1532", "There is no capturing group named '{0}' in this regular expression."),
|
|
9815
|
-
|
|
9816
|
-
|
|
9816
|
+
This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression: diag(1533, 1 /* Error */, "This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_r_1533", "This backreference refers to a group that does not exist. There are only {0} capturing groups in this regular expression."),
|
|
9817
|
+
This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups: diag(1534, 1 /* Error */, "This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups_1534", "This backreference is invalid because the containing regular expression contains no capturing groups."),
|
|
9817
9818
|
This_character_cannot_be_escaped_in_a_regular_expression: diag(1535, 1 /* Error */, "This_character_cannot_be_escaped_in_a_regular_expression_1535", "This character cannot be escaped in a regular expression."),
|
|
9818
9819
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, 1 /* Error */, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
9819
9820
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, 1 /* Error */, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
@@ -12642,7 +12643,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
12642
12643
|
tokenFlags |= 2048 /* ContainsInvalidEscape */;
|
|
12643
12644
|
if (isRegularExpression || shouldEmitInvalidEscapeError) {
|
|
12644
12645
|
const code = parseInt(text.substring(start2 + 1, pos), 8);
|
|
12645
|
-
|
|
12646
|
+
if (isRegularExpression !== "annex-b") {
|
|
12647
|
+
error2(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start2, pos - start2, "\\x" + code.toString(16).padStart(2, "0"));
|
|
12648
|
+
}
|
|
12646
12649
|
return String.fromCharCode(code);
|
|
12647
12650
|
}
|
|
12648
12651
|
return text.substring(start2, pos);
|
|
@@ -12673,7 +12676,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
12673
12676
|
case 117 /* u */:
|
|
12674
12677
|
if ((!isRegularExpression || shouldEmitInvalidEscapeError) && pos < end && text.charCodeAt(pos) === 123 /* openBrace */) {
|
|
12675
12678
|
pos -= 2;
|
|
12676
|
-
return scanExtendedUnicodeEscape(isRegularExpression || shouldEmitInvalidEscapeError);
|
|
12679
|
+
return scanExtendedUnicodeEscape(!!isRegularExpression || shouldEmitInvalidEscapeError);
|
|
12677
12680
|
}
|
|
12678
12681
|
for (; pos < start2 + 6; pos++) {
|
|
12679
12682
|
if (!(pos < end && isHexDigit(text.charCodeAt(pos)))) {
|
|
@@ -12723,7 +12726,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
12723
12726
|
case 8233 /* paragraphSeparator */:
|
|
12724
12727
|
return "";
|
|
12725
12728
|
default:
|
|
12726
|
-
if (isRegularExpression && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
|
|
12729
|
+
if (isRegularExpression === true && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) {
|
|
12727
12730
|
error2(Diagnostics.This_character_cannot_be_escaped_in_a_regular_expression, pos - 2, 2);
|
|
12728
12731
|
}
|
|
12729
12732
|
return String.fromCharCode(ch);
|
|
@@ -13418,7 +13421,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13418
13421
|
pos = tokenStart + 1;
|
|
13419
13422
|
return token = 64 /* EqualsToken */;
|
|
13420
13423
|
}
|
|
13421
|
-
function reScanSlashToken() {
|
|
13424
|
+
function reScanSlashToken(reportErrors2) {
|
|
13422
13425
|
if (token === 44 /* SlashToken */ || token === 69 /* SlashEqualsToken */) {
|
|
13423
13426
|
let p = tokenStart + 1;
|
|
13424
13427
|
let inEscape = false;
|
|
@@ -13457,38 +13460,54 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13457
13460
|
if (!isIdentifierPart(ch, languageVersion)) {
|
|
13458
13461
|
break;
|
|
13459
13462
|
}
|
|
13460
|
-
|
|
13461
|
-
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13463
|
+
if (reportErrors2) {
|
|
13464
|
+
const flag = characterToRegularExpressionFlag(String.fromCharCode(ch));
|
|
13465
|
+
if (flag === void 0) {
|
|
13466
|
+
error2(Diagnostics.Unknown_regular_expression_flag, p, 1);
|
|
13467
|
+
} else if (regExpFlags & flag) {
|
|
13468
|
+
error2(Diagnostics.Duplicate_regular_expression_flag, p, 1);
|
|
13469
|
+
} else if (((regExpFlags | flag) & 96 /* UnicodeMode */) === 96 /* UnicodeMode */) {
|
|
13470
|
+
error2(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1);
|
|
13471
|
+
} else {
|
|
13472
|
+
regExpFlags |= flag;
|
|
13473
|
+
const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag);
|
|
13474
|
+
if (languageVersion < availableFrom) {
|
|
13475
|
+
error2(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, p, 1, getNameOfScriptTarget(availableFrom));
|
|
13476
|
+
}
|
|
13472
13477
|
}
|
|
13473
13478
|
}
|
|
13474
13479
|
p++;
|
|
13475
13480
|
}
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
+
if (reportErrors2) {
|
|
13482
|
+
pos = tokenStart + 1;
|
|
13483
|
+
const saveTokenPos = tokenStart;
|
|
13484
|
+
const saveTokenFlags = tokenFlags;
|
|
13485
|
+
scanRegularExpressionWorker(
|
|
13486
|
+
text,
|
|
13487
|
+
endOfBody,
|
|
13488
|
+
regExpFlags,
|
|
13489
|
+
isUnterminated,
|
|
13490
|
+
/*annexB*/
|
|
13491
|
+
true
|
|
13492
|
+
);
|
|
13493
|
+
if (!isUnterminated) {
|
|
13494
|
+
pos = p;
|
|
13495
|
+
}
|
|
13496
|
+
tokenStart = saveTokenPos;
|
|
13497
|
+
tokenFlags = saveTokenFlags;
|
|
13498
|
+
} else {
|
|
13481
13499
|
pos = p;
|
|
13482
13500
|
}
|
|
13483
|
-
tokenStart = saveTokenPos;
|
|
13484
|
-
tokenFlags = saveTokenFlags;
|
|
13485
13501
|
tokenValue = text.substring(tokenStart, pos);
|
|
13486
13502
|
token = 14 /* RegularExpressionLiteral */;
|
|
13487
13503
|
}
|
|
13488
13504
|
return token;
|
|
13489
|
-
function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated) {
|
|
13490
|
-
const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
|
|
13505
|
+
function scanRegularExpressionWorker(text2, end2, regExpFlags, isUnterminated, annexB) {
|
|
13491
13506
|
const unicodeSetsMode = !!(regExpFlags & 64 /* UnicodeSets */);
|
|
13507
|
+
const unicodeMode = !!(regExpFlags & 96 /* UnicodeMode */);
|
|
13508
|
+
if (unicodeMode) {
|
|
13509
|
+
annexB = false;
|
|
13510
|
+
}
|
|
13492
13511
|
let mayContainStrings = false;
|
|
13493
13512
|
let numberOfCapturingGroups = 0;
|
|
13494
13513
|
const groupSpecifiers = /* @__PURE__ */ new Set();
|
|
@@ -13539,7 +13558,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13539
13558
|
case 61 /* equals */:
|
|
13540
13559
|
case 33 /* exclamation */:
|
|
13541
13560
|
pos++;
|
|
13542
|
-
isPreviousTermQuantifiable =
|
|
13561
|
+
isPreviousTermQuantifiable = annexB;
|
|
13543
13562
|
break;
|
|
13544
13563
|
case 60 /* lessThan */:
|
|
13545
13564
|
const groupNameStart = pos;
|
|
@@ -13718,7 +13737,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13718
13737
|
break;
|
|
13719
13738
|
}
|
|
13720
13739
|
default:
|
|
13721
|
-
Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(
|
|
13740
|
+
Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(
|
|
13741
|
+
/*atomEscape*/
|
|
13742
|
+
true
|
|
13743
|
+
));
|
|
13722
13744
|
break;
|
|
13723
13745
|
}
|
|
13724
13746
|
}
|
|
@@ -13733,7 +13755,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13733
13755
|
}
|
|
13734
13756
|
return false;
|
|
13735
13757
|
}
|
|
13736
|
-
function scanCharacterEscape() {
|
|
13758
|
+
function scanCharacterEscape(atomEscape) {
|
|
13737
13759
|
Debug.assertEqual(text2.charCodeAt(pos - 1), 92 /* backslash */);
|
|
13738
13760
|
let ch = text2.charCodeAt(pos);
|
|
13739
13761
|
switch (ch) {
|
|
@@ -13746,6 +13768,9 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13746
13768
|
}
|
|
13747
13769
|
if (unicodeMode) {
|
|
13748
13770
|
error2(Diagnostics.c_must_be_followed_by_an_ASCII_letter, pos - 2, 2);
|
|
13771
|
+
} else if (atomEscape && annexB) {
|
|
13772
|
+
pos--;
|
|
13773
|
+
return "\\";
|
|
13749
13774
|
}
|
|
13750
13775
|
return String.fromCharCode(ch);
|
|
13751
13776
|
case 94 /* caret */:
|
|
@@ -13775,7 +13800,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13775
13800
|
/*shouldEmitInvalidEscapeError*/
|
|
13776
13801
|
unicodeMode,
|
|
13777
13802
|
/*isRegularExpression*/
|
|
13778
|
-
true
|
|
13803
|
+
annexB ? "annex-b" : true
|
|
13779
13804
|
);
|
|
13780
13805
|
}
|
|
13781
13806
|
}
|
|
@@ -13815,12 +13840,12 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
13815
13840
|
if (isClassContentExit(ch2)) {
|
|
13816
13841
|
return;
|
|
13817
13842
|
}
|
|
13818
|
-
if (!minCharacter) {
|
|
13843
|
+
if (!minCharacter && !annexB) {
|
|
13819
13844
|
error2(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, minStart, pos - 1 - minStart);
|
|
13820
13845
|
}
|
|
13821
13846
|
const maxStart = pos;
|
|
13822
13847
|
const maxCharacter = scanClassAtom();
|
|
13823
|
-
if (!maxCharacter) {
|
|
13848
|
+
if (!maxCharacter && !annexB) {
|
|
13824
13849
|
error2(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, maxStart, pos - maxStart);
|
|
13825
13850
|
continue;
|
|
13826
13851
|
}
|
|
@@ -14103,7 +14128,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
14103
14128
|
pos++;
|
|
14104
14129
|
return String.fromCharCode(ch2);
|
|
14105
14130
|
default:
|
|
14106
|
-
return scanCharacterEscape(
|
|
14131
|
+
return scanCharacterEscape(
|
|
14132
|
+
/*atomEscape*/
|
|
14133
|
+
false
|
|
14134
|
+
);
|
|
14107
14135
|
}
|
|
14108
14136
|
} else if (ch === text2.charCodeAt(pos + 1)) {
|
|
14109
14137
|
switch (ch) {
|
|
@@ -14160,7 +14188,10 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
14160
14188
|
if (scanCharacterClassEscape()) {
|
|
14161
14189
|
return "";
|
|
14162
14190
|
}
|
|
14163
|
-
return scanCharacterEscape(
|
|
14191
|
+
return scanCharacterEscape(
|
|
14192
|
+
/*atomEscape*/
|
|
14193
|
+
false
|
|
14194
|
+
);
|
|
14164
14195
|
}
|
|
14165
14196
|
} else {
|
|
14166
14197
|
return scanSourceCharacter();
|
|
@@ -14275,11 +14306,11 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
|
|
|
14275
14306
|
}
|
|
14276
14307
|
});
|
|
14277
14308
|
forEach(decimalEscapes, (escape) => {
|
|
14278
|
-
if (escape.value > numberOfCapturingGroups) {
|
|
14309
|
+
if (!annexB && escape.value > numberOfCapturingGroups) {
|
|
14279
14310
|
if (numberOfCapturingGroups) {
|
|
14280
|
-
error2(Diagnostics.
|
|
14311
|
+
error2(Diagnostics.This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression, escape.pos, escape.end - escape.pos, numberOfCapturingGroups);
|
|
14281
14312
|
} else {
|
|
14282
|
-
error2(Diagnostics.
|
|
14313
|
+
error2(Diagnostics.This_backreference_is_invalid_because_the_containing_regular_expression_contains_no_capturing_groups, escape.pos, escape.end - escape.pos);
|
|
14283
14314
|
}
|
|
14284
14315
|
}
|
|
14285
14316
|
});
|
|
@@ -50076,6 +50107,7 @@ function createTypeChecker(host) {
|
|
|
50076
50107
|
var requestedExternalEmitHelperNames = /* @__PURE__ */ new Set();
|
|
50077
50108
|
var requestedExternalEmitHelpers;
|
|
50078
50109
|
var externalHelpersModule;
|
|
50110
|
+
var scanner2;
|
|
50079
50111
|
var Symbol47 = objectAllocator.getSymbolConstructor();
|
|
50080
50112
|
var Type28 = objectAllocator.getTypeConstructor();
|
|
50081
50113
|
var Signature14 = objectAllocator.getSignatureConstructor();
|
|
@@ -54935,7 +54967,8 @@ function createTypeChecker(host) {
|
|
|
54935
54967
|
deepCloneOrReuseNode,
|
|
54936
54968
|
/*context*/
|
|
54937
54969
|
void 0,
|
|
54938
|
-
deepCloneOrReuseNodes
|
|
54970
|
+
deepCloneOrReuseNodes,
|
|
54971
|
+
deepCloneOrReuseNode
|
|
54939
54972
|
)), node);
|
|
54940
54973
|
}
|
|
54941
54974
|
function deepCloneOrReuseNodes(nodes, visitor, test, start, count) {
|
|
@@ -75914,6 +75947,53 @@ function createTypeChecker(host) {
|
|
|
75914
75947
|
return signatureList.length === 1 ? signatureList[0] : createUnionSignature(signatureList[0], signatureList);
|
|
75915
75948
|
}
|
|
75916
75949
|
}
|
|
75950
|
+
function checkGrammarRegularExpressionLiteral(node) {
|
|
75951
|
+
const sourceFile = getSourceFileOfNode(node);
|
|
75952
|
+
if (!hasParseDiagnostics(sourceFile)) {
|
|
75953
|
+
let lastError;
|
|
75954
|
+
scanner2 ?? (scanner2 = createScanner(
|
|
75955
|
+
99 /* ESNext */,
|
|
75956
|
+
/*skipTrivia*/
|
|
75957
|
+
true
|
|
75958
|
+
));
|
|
75959
|
+
scanner2.setScriptTarget(sourceFile.languageVersion);
|
|
75960
|
+
scanner2.setLanguageVariant(sourceFile.languageVariant);
|
|
75961
|
+
scanner2.setOnError((message, length2, arg0) => {
|
|
75962
|
+
const start = scanner2.getTokenEnd();
|
|
75963
|
+
if (message.category === 3 /* Message */ && lastError && start === lastError.start && length2 === lastError.length) {
|
|
75964
|
+
const error3 = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length2, message, arg0);
|
|
75965
|
+
addRelatedInfo(lastError, error3);
|
|
75966
|
+
} else if (!lastError || start !== lastError.start) {
|
|
75967
|
+
lastError = createFileDiagnostic(sourceFile, start, length2, message, arg0);
|
|
75968
|
+
diagnostics.add(lastError);
|
|
75969
|
+
}
|
|
75970
|
+
});
|
|
75971
|
+
scanner2.setText(sourceFile.text, node.pos, node.end - node.pos);
|
|
75972
|
+
try {
|
|
75973
|
+
scanner2.scan();
|
|
75974
|
+
Debug.assert(scanner2.reScanSlashToken(
|
|
75975
|
+
/*reportErrors*/
|
|
75976
|
+
true
|
|
75977
|
+
) === 14 /* RegularExpressionLiteral */, "Expected scanner to rescan RegularExpressionLiteral");
|
|
75978
|
+
return !!lastError;
|
|
75979
|
+
} finally {
|
|
75980
|
+
scanner2.setText("");
|
|
75981
|
+
scanner2.setOnError(
|
|
75982
|
+
/*onError*/
|
|
75983
|
+
void 0
|
|
75984
|
+
);
|
|
75985
|
+
}
|
|
75986
|
+
}
|
|
75987
|
+
return false;
|
|
75988
|
+
}
|
|
75989
|
+
function checkRegularExpressionLiteral(node) {
|
|
75990
|
+
const nodeLinks2 = getNodeLinks(node);
|
|
75991
|
+
if (!(nodeLinks2.flags & 1 /* TypeChecked */)) {
|
|
75992
|
+
nodeLinks2.flags |= 1 /* TypeChecked */;
|
|
75993
|
+
addLazyDiagnostic(() => checkGrammarRegularExpressionLiteral(node));
|
|
75994
|
+
}
|
|
75995
|
+
return globalRegExpType;
|
|
75996
|
+
}
|
|
75917
75997
|
function checkSpreadExpression(node, checkMode) {
|
|
75918
75998
|
if (languageVersion < 2 /* SpreadElements */) {
|
|
75919
75999
|
checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? 1536 /* SpreadIncludes */ : 1024 /* SpreadArray */);
|
|
@@ -81817,7 +81897,7 @@ function createTypeChecker(host) {
|
|
|
81817
81897
|
parent2 = parent2.parent;
|
|
81818
81898
|
}
|
|
81819
81899
|
if (operator === 56 /* AmpersandAmpersandToken */ || isIfStatement(parent2)) {
|
|
81820
|
-
|
|
81900
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent2) ? parent2.thenStatement : void 0);
|
|
81821
81901
|
}
|
|
81822
81902
|
checkTruthinessOfType(leftType, node.left);
|
|
81823
81903
|
}
|
|
@@ -82375,7 +82455,7 @@ function createTypeChecker(host) {
|
|
|
82375
82455
|
}
|
|
82376
82456
|
function checkConditionalExpression(node, checkMode) {
|
|
82377
82457
|
const type = checkTruthinessExpression(node.condition, checkMode);
|
|
82378
|
-
|
|
82458
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.condition, type, node.whenTrue);
|
|
82379
82459
|
const type1 = checkExpression(node.whenTrue, checkMode);
|
|
82380
82460
|
const type2 = checkExpression(node.whenFalse, checkMode);
|
|
82381
82461
|
return getUnionType([type1, type2], 2 /* Subtype */);
|
|
@@ -82848,7 +82928,7 @@ function createTypeChecker(host) {
|
|
|
82848
82928
|
case 228 /* TemplateExpression */:
|
|
82849
82929
|
return checkTemplateExpression(node);
|
|
82850
82930
|
case 14 /* RegularExpressionLiteral */:
|
|
82851
|
-
return
|
|
82931
|
+
return checkRegularExpressionLiteral(node);
|
|
82852
82932
|
case 209 /* ArrayLiteralExpression */:
|
|
82853
82933
|
return checkArrayLiteral(node, checkMode, forceTuple);
|
|
82854
82934
|
case 210 /* ObjectLiteralExpression */:
|
|
@@ -85423,14 +85503,14 @@ function createTypeChecker(host) {
|
|
|
85423
85503
|
function checkIfStatement(node) {
|
|
85424
85504
|
checkGrammarStatementInAmbientContext(node);
|
|
85425
85505
|
const type = checkTruthinessExpression(node.expression);
|
|
85426
|
-
|
|
85506
|
+
checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.expression, type, node.thenStatement);
|
|
85427
85507
|
checkSourceElement(node.thenStatement);
|
|
85428
85508
|
if (node.thenStatement.kind === 242 /* EmptyStatement */) {
|
|
85429
85509
|
error2(node.thenStatement, Diagnostics.The_body_of_an_if_statement_cannot_be_the_empty_statement);
|
|
85430
85510
|
}
|
|
85431
85511
|
checkSourceElement(node.elseStatement);
|
|
85432
85512
|
}
|
|
85433
|
-
function
|
|
85513
|
+
function checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(condExpr, condType, body) {
|
|
85434
85514
|
if (!strictNullChecks)
|
|
85435
85515
|
return;
|
|
85436
85516
|
bothHelper(condExpr, body);
|
|
@@ -85452,6 +85532,10 @@ function createTypeChecker(host) {
|
|
|
85452
85532
|
return;
|
|
85453
85533
|
}
|
|
85454
85534
|
const type = location === condExpr2 ? condType : checkTruthinessExpression(location);
|
|
85535
|
+
if (type.flags & 1024 /* EnumLiteral */ && isPropertyAccessExpression(location) && (getNodeLinks(location.expression).resolvedSymbol ?? unknownSymbol).flags & 384 /* Enum */) {
|
|
85536
|
+
error2(location, Diagnostics.This_condition_will_always_return_0, !!type.value ? "true" : "false");
|
|
85537
|
+
return;
|
|
85538
|
+
}
|
|
85455
85539
|
const isPropertyExpressionCast = isPropertyAccessExpression(location) && isTypeAssertion(location.expression);
|
|
85456
85540
|
if (!hasTypeFacts(type, 4194304 /* Truthy */) || isPropertyExpressionCast)
|
|
85457
85541
|
return;
|
|
@@ -87897,7 +87981,7 @@ function createTypeChecker(host) {
|
|
|
87897
87981
|
if (checkGrammarModuleElementContext(node, isInJSFile(node) ? Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
|
|
87898
87982
|
return;
|
|
87899
87983
|
}
|
|
87900
|
-
if (!checkGrammarModifiers(node) &&
|
|
87984
|
+
if (!checkGrammarModifiers(node) && node.modifiers) {
|
|
87901
87985
|
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
|
|
87902
87986
|
}
|
|
87903
87987
|
if (checkExternalImportOrExportDeclaration(node)) {
|
|
@@ -141564,6 +141648,44 @@ var optionsRedundantWithVerbatimModuleSyntax = /* @__PURE__ */ new Set([
|
|
|
141564
141648
|
"isolatedModules"
|
|
141565
141649
|
]);
|
|
141566
141650
|
function transpileModule(input, transpileOptions) {
|
|
141651
|
+
return transpileWorker(
|
|
141652
|
+
input,
|
|
141653
|
+
transpileOptions,
|
|
141654
|
+
/*declaration*/
|
|
141655
|
+
false
|
|
141656
|
+
);
|
|
141657
|
+
}
|
|
141658
|
+
function transpileDeclaration(input, transpileOptions) {
|
|
141659
|
+
return transpileWorker(
|
|
141660
|
+
input,
|
|
141661
|
+
transpileOptions,
|
|
141662
|
+
/*declaration*/
|
|
141663
|
+
true
|
|
141664
|
+
);
|
|
141665
|
+
}
|
|
141666
|
+
var barebonesLibContent = `/// <reference no-default-lib="true"/>
|
|
141667
|
+
interface Boolean {}
|
|
141668
|
+
interface Function {}
|
|
141669
|
+
interface CallableFunction {}
|
|
141670
|
+
interface NewableFunction {}
|
|
141671
|
+
interface IArguments {}
|
|
141672
|
+
interface Number {}
|
|
141673
|
+
interface Object {}
|
|
141674
|
+
interface RegExp {}
|
|
141675
|
+
interface String {}
|
|
141676
|
+
interface Array<T> { length: number; [n: number]: T; }
|
|
141677
|
+
interface SymbolConstructor {
|
|
141678
|
+
(desc?: string | number): symbol;
|
|
141679
|
+
for(name: string): symbol;
|
|
141680
|
+
readonly toStringTag: symbol;
|
|
141681
|
+
}
|
|
141682
|
+
declare var Symbol: SymbolConstructor;
|
|
141683
|
+
interface Symbol {
|
|
141684
|
+
readonly [Symbol.toStringTag]: string;
|
|
141685
|
+
}`;
|
|
141686
|
+
var barebonesLibName = "lib.d.ts";
|
|
141687
|
+
var barebonesLibSourceFile = createSourceFile(barebonesLibName, barebonesLibContent, { languageVersion: 99 /* Latest */ });
|
|
141688
|
+
function transpileWorker(input, transpileOptions, declaration) {
|
|
141567
141689
|
const diagnostics = [];
|
|
141568
141690
|
const options = transpileOptions.compilerOptions ? fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics) : {};
|
|
141569
141691
|
const defaultOptions = getDefaultCompilerOptions2();
|
|
@@ -141580,9 +141702,16 @@ function transpileModule(input, transpileOptions) {
|
|
|
141580
141702
|
}
|
|
141581
141703
|
options.suppressOutputPathCheck = true;
|
|
141582
141704
|
options.allowNonTsExtensions = true;
|
|
141705
|
+
if (declaration) {
|
|
141706
|
+
options.declaration = true;
|
|
141707
|
+
options.emitDeclarationOnly = true;
|
|
141708
|
+
options.isolatedDeclarations = true;
|
|
141709
|
+
} else {
|
|
141710
|
+
options.declaration = false;
|
|
141711
|
+
}
|
|
141583
141712
|
const newLine = getNewLineCharacter(options);
|
|
141584
141713
|
const compilerHost = {
|
|
141585
|
-
getSourceFile: (fileName) => fileName === normalizePath(inputFileName) ? sourceFile : void 0,
|
|
141714
|
+
getSourceFile: (fileName) => fileName === normalizePath(inputFileName) ? sourceFile : fileName === normalizePath(barebonesLibName) ? barebonesLibSourceFile : void 0,
|
|
141586
141715
|
writeFile: (name, text) => {
|
|
141587
141716
|
if (fileExtensionIs(name, ".map")) {
|
|
141588
141717
|
Debug.assertEqual(sourceMapText, void 0, "Unexpected multiple source map outputs, file:", name);
|
|
@@ -141592,12 +141721,12 @@ function transpileModule(input, transpileOptions) {
|
|
|
141592
141721
|
outputText = text;
|
|
141593
141722
|
}
|
|
141594
141723
|
},
|
|
141595
|
-
getDefaultLibFileName: () =>
|
|
141724
|
+
getDefaultLibFileName: () => barebonesLibName,
|
|
141596
141725
|
useCaseSensitiveFileNames: () => false,
|
|
141597
141726
|
getCanonicalFileName: (fileName) => fileName,
|
|
141598
141727
|
getCurrentDirectory: () => "",
|
|
141599
141728
|
getNewLine: () => newLine,
|
|
141600
|
-
fileExists: (fileName) => fileName === inputFileName,
|
|
141729
|
+
fileExists: (fileName) => fileName === inputFileName || !!declaration && fileName === barebonesLibName,
|
|
141601
141730
|
readFile: () => "",
|
|
141602
141731
|
directoryExists: () => true,
|
|
141603
141732
|
getDirectories: () => []
|
|
@@ -141627,7 +141756,8 @@ function transpileModule(input, transpileOptions) {
|
|
|
141627
141756
|
}
|
|
141628
141757
|
let outputText;
|
|
141629
141758
|
let sourceMapText;
|
|
141630
|
-
const
|
|
141759
|
+
const inputs = declaration ? [inputFileName, barebonesLibName] : [inputFileName];
|
|
141760
|
+
const program = createProgram(inputs, options, compilerHost);
|
|
141631
141761
|
if (transpileOptions.reportDiagnostics) {
|
|
141632
141762
|
addRange(
|
|
141633
141763
|
/*to*/
|
|
@@ -141642,7 +141772,7 @@ function transpileModule(input, transpileOptions) {
|
|
|
141642
141772
|
program.getOptionsDiagnostics()
|
|
141643
141773
|
);
|
|
141644
141774
|
}
|
|
141645
|
-
program.emit(
|
|
141775
|
+
const result = program.emit(
|
|
141646
141776
|
/*targetSourceFile*/
|
|
141647
141777
|
void 0,
|
|
141648
141778
|
/*writeFile*/
|
|
@@ -141650,8 +141780,16 @@ function transpileModule(input, transpileOptions) {
|
|
|
141650
141780
|
/*cancellationToken*/
|
|
141651
141781
|
void 0,
|
|
141652
141782
|
/*emitOnlyDtsFiles*/
|
|
141653
|
-
|
|
141654
|
-
transpileOptions.transformers
|
|
141783
|
+
declaration,
|
|
141784
|
+
transpileOptions.transformers,
|
|
141785
|
+
/*forceDtsEmit*/
|
|
141786
|
+
declaration
|
|
141787
|
+
);
|
|
141788
|
+
addRange(
|
|
141789
|
+
/*to*/
|
|
141790
|
+
diagnostics,
|
|
141791
|
+
/*from*/
|
|
141792
|
+
result.diagnostics
|
|
141655
141793
|
);
|
|
141656
141794
|
if (outputText === void 0)
|
|
141657
141795
|
return Debug.fail("Output generation failed");
|
|
@@ -180020,6 +180158,7 @@ __export(ts_exports2, {
|
|
|
180020
180158
|
transformSystemModule: () => transformSystemModule,
|
|
180021
180159
|
transformTypeScript: () => transformTypeScript,
|
|
180022
180160
|
transpile: () => transpile,
|
|
180161
|
+
transpileDeclaration: () => transpileDeclaration,
|
|
180023
180162
|
transpileModule: () => transpileModule,
|
|
180024
180163
|
transpileOptionValueCompilerOptions: () => transpileOptionValueCompilerOptions,
|
|
180025
180164
|
tryAddToSet: () => tryAddToSet,
|
|
@@ -194446,6 +194585,7 @@ if (typeof console !== "undefined") {
|
|
|
194446
194585
|
transformSystemModule,
|
|
194447
194586
|
transformTypeScript,
|
|
194448
194587
|
transpile,
|
|
194588
|
+
transpileDeclaration,
|
|
194449
194589
|
transpileModule,
|
|
194450
194590
|
transpileOptionValueCompilerOptions,
|
|
194451
194591
|
tryAddToSet,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "typescript",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "5.5.0-dev.
|
|
5
|
+
"version": "5.5.0-dev.20240425",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"node": "20.1.0",
|
|
111
111
|
"npm": "8.19.4"
|
|
112
112
|
},
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "9504b7576a6489a3d5149db451b6ec8f772d67d4"
|
|
114
114
|
}
|