Skip to content

Commit 47b29cc

Browse files
committed
Merge branch 'master' into removePromiseResolveValueOptionality
2 parents a1068ff + 838a5e6 commit 47b29cc

File tree

54 files changed

+791
-67
lines changed

Some content is hidden

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

54 files changed

+791
-67
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ See below for examples.
176176

177177
### Tests for multiple files
178178

179-
When you need to multiple files in a single test, use the `filename` tag:
179+
When you need to mimic having multiple files in a single test to test features such as "import", use the `filename` tag:
180180

181181
```ts
182182
// @filename: file1.ts

Diff for: package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/compiler/binder.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,10 @@ namespace ts {
29742974
if (!isInJSFile(node) && !isFunctionSymbol(parentSymbol)) {
29752975
return;
29762976
}
2977+
const rootExpr = getLeftmostAccessExpression(node.left);
2978+
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)!?.flags & SymbolFlags.Alias) {
2979+
return;
2980+
}
29772981
// Fix up parent pointers since we're going to use these nodes before we bind into them
29782982
setParent(node.left, node);
29792983
setParent(node.right, node);

Diff for: src/compiler/checker.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ namespace ts {
24162416

24172417
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration | VariableDeclaration, dontResolveAlias: boolean): Symbol | undefined {
24182418
if (isVariableDeclaration(node) && node.initializer && isPropertyAccessExpression(node.initializer)) {
2419-
const name = (getLeftmostPropertyAccessExpression(node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
2419+
const name = (getLeftmostAccessExpression(node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
24202420
return isIdentifier(node.initializer.name)
24212421
? resolveSymbol(getPropertyOfType(resolveExternalModuleTypeByLiteral(name), node.initializer.name.escapedText))
24222422
: undefined;
@@ -2678,7 +2678,7 @@ namespace ts {
26782678
const suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol);
26792679
if (suggestion !== undefined) {
26802680
const suggestionName = symbolToString(suggestion);
2681-
const diagnostic = error(name, Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2, moduleName, declarationName, suggestionName);
2681+
const diagnostic = error(name, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName);
26822682
if (suggestion.valueDeclaration) {
26832683
addRelatedInfo(diagnostic,
26842684
createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName)
@@ -3057,7 +3057,12 @@ namespace ts {
30573057
symbol = getMergedSymbol(getSymbol(getExportsOfSymbol(namespace), right.escapedText, meaning));
30583058
if (!symbol) {
30593059
if (!ignoreErrors) {
3060-
error(right, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right));
3060+
const namespaceName = getFullyQualifiedName(namespace);
3061+
const declarationName = declarationNameToString(right);
3062+
const suggestion = getSuggestedSymbolForNonexistentModule(right, namespace);
3063+
suggestion ?
3064+
error(right, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, namespaceName, declarationName, symbolToString(suggestion)) :
3065+
error(right, Diagnostics.Namespace_0_has_no_exported_member_1, namespaceName, declarationName);
30613066
}
30623067
return undefined;
30633068
}
@@ -9709,7 +9714,7 @@ namespace ts {
97099714

97109715
// fill in any as-yet-unresolved late-bound members.
97119716
const lateSymbols = createSymbolTable() as UnderscoreEscapedMap<TransientSymbol>;
9712-
for (const decl of symbol.declarations) {
9717+
for (const decl of symbol.declarations || emptyArray) {
97139718
const members = getMembersOfDeclaration(decl);
97149719
if (members) {
97159720
for (const member of members) {

Diff for: src/compiler/diagnosticMessages.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@
27522752
"category": "Error",
27532753
"code": 2723
27542754
},
2755-
"Module '{0}' has no exported member '{1}'. Did you mean '{2}'?": {
2755+
"'{0}' has no exported member named '{1}'. Did you mean '{2}'?": {
27562756
"category": "Error",
27572757
"code": 2724
27582758
},
@@ -3029,7 +3029,6 @@
30293029
"code": 2792
30303030
},
30313031

3032-
30333032
"Import declaration '{0}' is using private name '{1}'.": {
30343033
"category": "Error",
30353034
"code": 4000

Diff for: src/compiler/emitter.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -4546,7 +4546,11 @@ namespace ts {
45464546
}
45474547
}
45484548

4549-
return getLiteralText(node, currentSourceFile!, neverAsciiEscape, jsxAttributeEscape);
4549+
const flags = (neverAsciiEscape ? GetLiteralTextFlags.NeverAsciiEscape : 0)
4550+
| (jsxAttributeEscape ? GetLiteralTextFlags.JsxAttributeEscape : 0)
4551+
| (printerOptions.terminateUnterminatedLiterals ? GetLiteralTextFlags.TerminateUnterminatedLiterals : 0);
4552+
4553+
return getLiteralText(node, currentSourceFile!, flags);
45504554
}
45514555

45524556
/**

Diff for: src/compiler/program.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ namespace ts {
28462846
&& !options.noResolve
28472847
&& i < file.imports.length
28482848
&& !elideImport
2849-
&& !(isJsFile && !options.allowJs)
2849+
&& !(isJsFile && !getAllowJSCompilerOption(options))
28502850
&& (isInJSFile(file.imports[i]) || !(file.imports[i].flags & NodeFlags.JSDoc));
28512851

28522852
if (elideImport) {
@@ -3160,7 +3160,7 @@ namespace ts {
31603160
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields");
31613161
}
31623162

3163-
if (options.checkJs && !options.allowJs) {
3163+
if (options.checkJs && !getAllowJSCompilerOption(options)) {
31643164
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
31653165
}
31663166

@@ -3774,7 +3774,7 @@ namespace ts {
37743774
return options.jsx ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set;
37753775
}
37763776
function needAllowJs() {
3777-
return options.allowJs || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
3777+
return getAllowJSCompilerOption(options) || !getStrictOptionValue(options, "noImplicitAny") ? undefined : Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type;
37783778
}
37793779
function needResolveJsonModule() {
37803780
return options.resolveJsonModule ? undefined : Diagnostics.Module_0_was_resolved_to_1_but_resolveJsonModule_is_not_used;

Diff for: src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7652,6 +7652,7 @@ namespace ts {
76527652
/*@internal*/ recordInternalSection?: boolean;
76537653
/*@internal*/ stripInternal?: boolean;
76547654
/*@internal*/ preserveSourceNewlines?: boolean;
7655+
/*@internal*/ terminateUnterminatedLiterals?: boolean;
76557656
/*@internal*/ relativeToBuildInfo?: (path: string) => string;
76567657
}
76577658

Diff for: src/compiler/utilities.ts

+25-10
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,17 @@ namespace ts {
562562
return emitNode && emitNode.flags || 0;
563563
}
564564

565-
export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile, neverAsciiEscape: boolean | undefined, jsxAttributeEscape: boolean) {
565+
export const enum GetLiteralTextFlags {
566+
None = 0,
567+
NeverAsciiEscape = 1 << 0,
568+
JsxAttributeEscape = 1 << 1,
569+
TerminateUnterminatedLiterals = 1 << 2,
570+
}
571+
572+
export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile, flags: GetLiteralTextFlags) {
566573
// If we don't need to downlevel and we can reach the original source text using
567574
// the node's parent reference, then simply get the text as it was originally written.
568-
if (!nodeIsSynthesized(node) && node.parent && !(
575+
if (!nodeIsSynthesized(node) && node.parent && !(flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated) && !(
569576
(isNumericLiteral(node) && node.numericLiteralFlags & TokenFlags.ContainsSeparator) ||
570577
isBigIntLiteral(node)
571578
)) {
@@ -576,8 +583,8 @@ namespace ts {
576583
// or a (possibly escaped) quoted form of the original text if it's string-like.
577584
switch (node.kind) {
578585
case SyntaxKind.StringLiteral: {
579-
const escapeText = jsxAttributeEscape ? escapeJsxAttributeString :
580-
neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString :
586+
const escapeText = flags & GetLiteralTextFlags.JsxAttributeEscape ? escapeJsxAttributeString :
587+
flags & GetLiteralTextFlags.NeverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString :
581588
escapeNonAsciiString;
582589
if ((<StringLiteral>node).singleQuote) {
583590
return "'" + escapeText(node.text, CharacterCodes.singleQuote) + "'";
@@ -592,7 +599,7 @@ namespace ts {
592599
case SyntaxKind.TemplateTail: {
593600
// If a NoSubstitutionTemplateLiteral appears to have a substitution in it, the original text
594601
// had to include a backslash: `not \${a} substitution`.
595-
const escapeText = neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString :
602+
const escapeText = flags & GetLiteralTextFlags.NeverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? escapeString :
596603
escapeNonAsciiString;
597604

598605
const rawText = (<TemplateLiteralLikeNode>node).rawText || escapeTemplateSubstitution(escapeText(node.text, CharacterCodes.backtick));
@@ -610,7 +617,11 @@ namespace ts {
610617
}
611618
case SyntaxKind.NumericLiteral:
612619
case SyntaxKind.BigIntLiteral:
620+
return node.text;
613621
case SyntaxKind.RegularExpressionLiteral:
622+
if (flags & GetLiteralTextFlags.TerminateUnterminatedLiterals && node.isUnterminated) {
623+
return node.text + (node.text.charCodeAt(node.text.length - 1) === CharacterCodes.backslash ? " /" : "/");
624+
}
614625
return node.text;
615626
}
616627

@@ -1858,7 +1869,7 @@ namespace ts {
18581869

18591870
export function getExternalModuleRequireArgument(node: Node) {
18601871
return isRequireVariableDeclaration(node, /*requireStringLiteralLikeArgument*/ true)
1861-
&& (getLeftmostPropertyAccessExpression(node.initializer) as CallExpression).arguments[0] as StringLiteral;
1872+
&& (getLeftmostAccessExpression(node.initializer) as CallExpression).arguments[0] as StringLiteral;
18621873
}
18631874

18641875
export function isInternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration {
@@ -1929,7 +1940,7 @@ namespace ts {
19291940
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration;
19301941
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration {
19311942
node = getRootDeclaration(node);
1932-
return isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostPropertyAccessExpression(node.initializer), requireStringLiteralLikeArgument);
1943+
return isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), requireStringLiteralLikeArgument);
19331944
}
19341945

19351946
export function isRequireVariableStatement(node: Node, requireStringLiteralLikeArgument = true): node is RequireVariableStatement {
@@ -5452,8 +5463,8 @@ namespace ts {
54525463
return node.kind === SyntaxKind.NamedImports || node.kind === SyntaxKind.NamedExports;
54535464
}
54545465

5455-
export function getLeftmostPropertyAccessExpression(expr: Expression): Expression {
5456-
while (isPropertyAccessExpression(expr)) {
5466+
export function getLeftmostAccessExpression(expr: Expression): Expression {
5467+
while (isAccessExpression(expr)) {
54575468
expr = expr.expression;
54585469
}
54595470
return expr;
@@ -5922,6 +5933,10 @@ namespace ts {
59225933
return compilerOptions[flag] === undefined ? !!compilerOptions.strict : !!compilerOptions[flag];
59235934
}
59245935

5936+
export function getAllowJSCompilerOption(compilerOptions: CompilerOptions): boolean {
5937+
return compilerOptions.allowJs === undefined ? !!compilerOptions.checkJs : compilerOptions.allowJs;
5938+
}
5939+
59255940
export function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
59265941
return oldOptions !== newOptions &&
59275942
semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
@@ -6375,7 +6390,7 @@ namespace ts {
63756390
export function getSupportedExtensions(options?: CompilerOptions): readonly Extension[];
63766391
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[];
63776392
export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]): readonly string[] {
6378-
const needJsExtensions = options && options.allowJs;
6393+
const needJsExtensions = options && getAllowJSCompilerOption(options);
63796394

63806395
if (!extraFileExtensions || extraFileExtensions.length === 0) {
63816396
return needJsExtensions ? allSupportedExtensions : supportedTSExtensions;

Diff for: src/harness/client.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ namespace ts.server {
757757
name: item.name,
758758
kind: item.kind,
759759
kindModifiers: item.kindModifiers,
760+
containerName: item.containerName,
760761
span: this.decodeSpan(item.span, item.file),
761762
selectionSpan: this.decodeSpan(item.selectionSpan, item.file)
762763
};
@@ -778,7 +779,7 @@ namespace ts.server {
778779

779780
provideCallHierarchyIncomingCalls(fileName: string, position: number) {
780781
const args = this.createFileLocationRequestArgs(fileName, position);
781-
const request = this.processRequest<protocol.ProvideCallHierarchyIncomingCallsRequest>(CommandNames.PrepareCallHierarchy, args);
782+
const request = this.processRequest<protocol.ProvideCallHierarchyIncomingCallsRequest>(CommandNames.ProvideCallHierarchyIncomingCalls, args);
782783
const response = this.processResponse<protocol.ProvideCallHierarchyIncomingCallsResponse>(request);
783784
return response.body.map(item => this.convertCallHierarchyIncomingCall(item));
784785
}
@@ -792,7 +793,7 @@ namespace ts.server {
792793

793794
provideCallHierarchyOutgoingCalls(fileName: string, position: number) {
794795
const args = this.createFileLocationRequestArgs(fileName, position);
795-
const request = this.processRequest<protocol.ProvideCallHierarchyOutgoingCallsRequest>(CommandNames.PrepareCallHierarchy, args);
796+
const request = this.processRequest<protocol.ProvideCallHierarchyOutgoingCallsRequest>(CommandNames.ProvideCallHierarchyOutgoingCalls, args);
796797
const response = this.processResponse<protocol.ProvideCallHierarchyOutgoingCallsResponse>(request);
797798
return response.body.map(item => this.convertCallHierarchyOutgoingCall(fileName, item));
798799
}

Diff for: src/harness/fourslashImpl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ namespace FourSlash {
623623
ts.forEachKey(this.inputFiles, fileName => {
624624
if (!ts.isAnySupportedFileExtension(fileName)
625625
|| Harness.getConfigNameFromFileName(fileName)
626-
|| !this.getProgram().getCompilerOptions().allowJs && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return;
626+
|| !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))) return;
627627
const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion);
628628
if (errors.length) {
629629
this.printErrorLog(/*expectErrors*/ false, errors);

Diff for: src/harness/harnessIO.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ namespace Harness {
469469
if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) {
470470
dtsFiles.push(file);
471471
}
472-
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && options.allowJs)) {
472+
else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && ts.getAllowJSCompilerOption(options))) {
473473
const declFile = findResultCodeFile(file.unitName);
474474
if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) {
475475
dtsFiles.push({ unitName: declFile.file, content: Utils.removeByteOrderMark(declFile.text) });

0 commit comments

Comments
 (0)