Skip to content

Commit 768660c

Browse files
committed
Merge branch 'main' into delayedVersionPaths
2 parents a499627 + 59e659a commit 768660c

File tree

549 files changed

+60770
-8470
lines changed

Some content is hidden

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

549 files changed

+60770
-8470
lines changed

package-lock.json

Lines changed: 305 additions & 301 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7735,23 +7735,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
77357735
}
77367736

77377737
function getPropertyNameNodeForSymbol(symbol: Symbol, context: NodeBuilderContext) {
7738+
const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed);
77387739
const singleQuote = !!length(symbol.declarations) && every(symbol.declarations, isSingleQuotedStringNamed);
7739-
const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote);
7740+
const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote, stringNamed);
77407741
if (fromNameType) {
77417742
return fromNameType;
77427743
}
77437744
const rawName = unescapeLeadingUnderscores(symbol.escapedName);
7744-
const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed);
77457745
return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
77467746
}
77477747

77487748
// See getNameForSymbolFromNameType for a stringy equivalent
7749-
function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote?: boolean) {
7749+
function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote?: boolean, stringNamed?: boolean) {
77507750
const nameType = getSymbolLinks(symbol).nameType;
77517751
if (nameType) {
77527752
if (nameType.flags & TypeFlags.StringOrNumberLiteral) {
77537753
const name = "" + (nameType as StringLiteralType | NumberLiteralType).value;
7754-
if (!isIdentifierText(name, getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
7754+
if (!isIdentifierText(name, getEmitScriptTarget(compilerOptions)) && (stringNamed || !isNumericLiteralName(name))) {
77557755
return factory.createStringLiteral(name, !!singleQuote);
77567756
}
77577757
if (isNumericLiteralName(name) && startsWith(name, "-")) {
@@ -34998,7 +34998,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3499834998
}
3499934999

3500035000
function hasEmptyObjectIntersection(type: Type): boolean {
35001-
return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && some((t as IntersectionType).types, isEmptyAnonymousObjectType));
35001+
return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && isEmptyAnonymousObjectType(getBaseConstraintOrType(t)));
3500235002
}
3500335003

3500435004
function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {

src/compiler/emitter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4862,7 +4862,14 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
48624862
}
48634863

48644864
function emitList(parentNode: Node | undefined, children: NodeArray<Node> | undefined, format: ListFormat, parenthesizerRule?: ParenthesizerRuleOrSelector<Node>, start?: number, count?: number) {
4865-
emitNodeList(emit, parentNode, children, format, parenthesizerRule, start, count);
4865+
emitNodeList(
4866+
emit,
4867+
parentNode,
4868+
children,
4869+
format | (parentNode && getEmitFlags(parentNode) & EmitFlags.MultiLine ? ListFormat.PreferNewLine : 0),
4870+
parenthesizerRule,
4871+
start,
4872+
count);
48664873
}
48674874

48684875
function emitExpressionList(parentNode: Node | undefined, children: NodeArray<Node> | undefined, format: ListFormat, parenthesizerRule?: ParenthesizerRuleOrSelector<Expression>, start?: number, count?: number) {

src/compiler/transformers/module/module.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -958,32 +958,57 @@ export function transformModule(context: TransformationContext): (x: SourceFile
958958
function createImportCallExpressionCommonJS(arg: Expression | undefined, isInlineable?: boolean): Expression {
959959
// import(x)
960960
// emit as
961-
// var _a;
962-
// (_a = x, Promise.resolve().then(() => require(_a)) /*CommonJs Require*/
961+
// Promise.resolve(`${x}`).then((s) => require(s)) /*CommonJs Require*/
963962
// We have to wrap require in then callback so that require is done in asynchronously
964963
// if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately
965-
// If the arg is not inlineable, we have to evaluate it in the current scope with a temp var
966-
const temp = arg && !isSimpleInlineableExpression(arg) && !isInlineable ? factory.createTempVariable(hoistVariableDeclaration) : undefined;
964+
// If the arg is not inlineable, we have to evaluate and ToString() it in the current scope
965+
// Otherwise, we inline it in require() so that it's statically analyzable
966+
const needSyncEval = arg && !isSimpleInlineableExpression(arg) && !isInlineable;
967+
967968
const promiseResolveCall = factory.createCallExpression(
968969
factory.createPropertyAccessExpression(factory.createIdentifier("Promise"), "resolve"),
969970
/*typeArguments*/ undefined,
970-
/*argumentsArray*/ [],
971+
/*argumentsArray*/ needSyncEval
972+
? languageVersion >= ScriptTarget.ES2015
973+
? [
974+
factory.createTemplateExpression(factory.createTemplateHead(""), [
975+
factory.createTemplateSpan(arg, factory.createTemplateTail("")),
976+
]),
977+
]
978+
: [
979+
factory.createCallExpression(
980+
factory.createPropertyAccessExpression(factory.createStringLiteral(""), "concat"),
981+
/*typeArguments*/ undefined,
982+
[arg]
983+
),
984+
]
985+
: []
971986
);
987+
972988
let requireCall: Expression = factory.createCallExpression(
973989
factory.createIdentifier("require"),
974990
/*typeArguments*/ undefined,
975-
temp ? [temp] : arg ? [arg] : [],
991+
needSyncEval ? [factory.createIdentifier("s")] : arg ? [arg] : [],
976992
);
977993
if (getESModuleInterop(compilerOptions)) {
978994
requireCall = emitHelpers().createImportStarHelper(requireCall);
979995
}
980996

997+
const parameters = needSyncEval
998+
? [
999+
factory.createParameterDeclaration(
1000+
/*modifiers*/ undefined,
1001+
/*dotDotDotToken*/ undefined,
1002+
/*name*/ "s"),
1003+
]
1004+
: [];
1005+
9811006
let func: FunctionExpression | ArrowFunction;
9821007
if (languageVersion >= ScriptTarget.ES2015) {
9831008
func = factory.createArrowFunction(
9841009
/*modifiers*/ undefined,
9851010
/*typeParameters*/ undefined,
986-
/*parameters*/ [],
1011+
/*parameters*/ parameters,
9871012
/*type*/ undefined,
9881013
/*equalsGreaterThanToken*/ undefined,
9891014
requireCall);
@@ -994,14 +1019,14 @@ export function transformModule(context: TransformationContext): (x: SourceFile
9941019
/*asteriskToken*/ undefined,
9951020
/*name*/ undefined,
9961021
/*typeParameters*/ undefined,
997-
/*parameters*/ [],
1022+
/*parameters*/ parameters,
9981023
/*type*/ undefined,
9991024
factory.createBlock([factory.createReturnStatement(requireCall)]));
10001025
}
10011026

10021027
const downleveledImport = factory.createCallExpression(factory.createPropertyAccessExpression(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]);
10031028

1004-
return temp === undefined ? downleveledImport : factory.createCommaListExpression([factory.createAssignment(temp, arg!), downleveledImport]);
1029+
return downleveledImport;
10051030
}
10061031

10071032
function getHelperExpressionForExport(node: ExportDeclaration, innerExpr: Expression) {

src/compiler/types.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7490,7 +7490,7 @@ export interface EmitNode {
74907490
helpers?: EmitHelper[]; // Emit helpers for the node
74917491
startsOnNewLine?: boolean; // If the node should begin on a new line
74927492
snippetElement?: SnippetElement; // Snippet element of the node
7493-
typeNode?: TypeNode; // VariableDeclaration type
7493+
typeNode?: TypeNode; // VariableDeclaration type
74947494
}
74957495

74967496
/** @internal */
@@ -7520,38 +7520,39 @@ export const enum SnippetKind {
75207520
export const enum EmitFlags {
75217521
None = 0,
75227522
SingleLine = 1 << 0, // The contents of this node should be emitted on a single line.
7523-
AdviseOnEmitNode = 1 << 1, // The printer should invoke the onEmitNode callback when printing this node.
7524-
NoSubstitution = 1 << 2, // Disables further substitution of an expression.
7525-
CapturesThis = 1 << 3, // The function captures a lexical `this`
7526-
NoLeadingSourceMap = 1 << 4, // Do not emit a leading source map location for this node.
7527-
NoTrailingSourceMap = 1 << 5, // Do not emit a trailing source map location for this node.
7523+
MultiLine = 1 << 1,
7524+
AdviseOnEmitNode = 1 << 2, // The printer should invoke the onEmitNode callback when printing this node.
7525+
NoSubstitution = 1 << 3, // Disables further substitution of an expression.
7526+
CapturesThis = 1 << 4, // The function captures a lexical `this`
7527+
NoLeadingSourceMap = 1 << 5, // Do not emit a leading source map location for this node.
7528+
NoTrailingSourceMap = 1 << 6, // Do not emit a trailing source map location for this node.
75287529
NoSourceMap = NoLeadingSourceMap | NoTrailingSourceMap, // Do not emit a source map location for this node.
7529-
NoNestedSourceMaps = 1 << 6, // Do not emit source map locations for children of this node.
7530-
NoTokenLeadingSourceMaps = 1 << 7, // Do not emit leading source map location for token nodes.
7531-
NoTokenTrailingSourceMaps = 1 << 8, // Do not emit trailing source map location for token nodes.
7530+
NoNestedSourceMaps = 1 << 7, // Do not emit source map locations for children of this node.
7531+
NoTokenLeadingSourceMaps = 1 << 8, // Do not emit leading source map location for token nodes.
7532+
NoTokenTrailingSourceMaps = 1 << 9, // Do not emit trailing source map location for token nodes.
75327533
NoTokenSourceMaps = NoTokenLeadingSourceMaps | NoTokenTrailingSourceMaps, // Do not emit source map locations for tokens of this node.
7533-
NoLeadingComments = 1 << 9, // Do not emit leading comments for this node.
7534-
NoTrailingComments = 1 << 10, // Do not emit trailing comments for this node.
7534+
NoLeadingComments = 1 << 10, // Do not emit leading comments for this node.
7535+
NoTrailingComments = 1 << 11, // Do not emit trailing comments for this node.
75357536
NoComments = NoLeadingComments | NoTrailingComments, // Do not emit comments for this node.
7536-
NoNestedComments = 1 << 11,
7537-
HelperName = 1 << 12, // The Identifier refers to an *unscoped* emit helper (one that is emitted at the top of the file)
7538-
ExportName = 1 << 13, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal).
7539-
LocalName = 1 << 14, // Ensure an export prefix is not added for an identifier that points to an exported declaration.
7540-
InternalName = 1 << 15, // The name is internal to an ES5 class body function.
7541-
Indented = 1 << 16, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter).
7542-
NoIndentation = 1 << 17, // Do not indent the node.
7543-
AsyncFunctionBody = 1 << 18,
7544-
ReuseTempVariableScope = 1 << 19, // Reuse the existing temp variable scope during emit.
7545-
CustomPrologue = 1 << 20, // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed).
7546-
NoHoisting = 1 << 21, // Do not hoist this declaration in --module system
7547-
HasEndOfDeclarationMarker = 1 << 22, // Declaration has an associated NotEmittedStatement to mark the end of the declaration
7548-
Iterator = 1 << 23, // The expression to a `yield*` should be treated as an Iterator when down-leveling, not an Iterable.
7549-
NoAsciiEscaping = 1 << 24, // When synthesizing nodes that lack an original node or textSourceNode, we want to write the text on the node with ASCII escaping substitutions.
7550-
/** @internal */ TypeScriptClassWrapper = 1 << 25, // The node is an IIFE class wrapper created by the ts transform.
7551-
/** @internal */ NeverApplyImportHelper = 1 << 26, // Indicates the node should never be wrapped with an import star helper (because, for example, it imports tslib itself)
7552-
/** @internal */ IgnoreSourceNewlines = 1 << 27, // Overrides `printerOptions.preserveSourceNewlines` to print this node (and all descendants) with default whitespace.
7553-
/** @internal */ Immutable = 1 << 28, // Indicates a node is a singleton intended to be reused in multiple locations. Any attempt to make further changes to the node will result in an error.
7554-
/** @internal */ IndirectCall = 1 << 29, // Emit CallExpression as an indirect call: `(0, f)()`
7537+
NoNestedComments = 1 << 12,
7538+
HelperName = 1 << 13, // The Identifier refers to an *unscoped* emit helper (one that is emitted at the top of the file)
7539+
ExportName = 1 << 14, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal).
7540+
LocalName = 1 << 15, // Ensure an export prefix is not added for an identifier that points to an exported declaration.
7541+
InternalName = 1 << 16, // The name is internal to an ES5 class body function.
7542+
Indented = 1 << 17, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter).
7543+
NoIndentation = 1 << 18, // Do not indent the node.
7544+
AsyncFunctionBody = 1 << 19,
7545+
ReuseTempVariableScope = 1 << 20, // Reuse the existing temp variable scope during emit.
7546+
CustomPrologue = 1 << 21, // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed).
7547+
NoHoisting = 1 << 22, // Do not hoist this declaration in --module system
7548+
HasEndOfDeclarationMarker = 1 << 23, // Declaration has an associated NotEmittedStatement to mark the end of the declaration
7549+
Iterator = 1 << 24, // The expression to a `yield*` should be treated as an Iterator when down-leveling, not an Iterable.
7550+
NoAsciiEscaping = 1 << 25, // When synthesizing nodes that lack an original node or textSourceNode, we want to write the text on the node with ASCII escaping substitutions.
7551+
/** @internal */ TypeScriptClassWrapper = 1 << 26, // The node is an IIFE class wrapper created by the ts transform.
7552+
/** @internal */ NeverApplyImportHelper = 1 << 27, // Indicates the node should never be wrapped with an import star helper (because, for example, it imports tslib itself)
7553+
/** @internal */ IgnoreSourceNewlines = 1 << 28, // Overrides `printerOptions.preserveSourceNewlines` to print this node (and all descendants) with default whitespace.
7554+
/** @internal */ Immutable = 1 << 29, // Indicates a node is a singleton intended to be reused in multiple locations. Any attempt to make further changes to the node will result in an error.
7555+
/** @internal */ IndirectCall = 1 << 30, // Emit CallExpression as an indirect call: `(0, f)()`
75557556
}
75567557

75577558
export interface EmitHelperBase {

src/jsTyping/jsTyping.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
removeFileExtension,
2727
removeMinAndVersionNumbers,
2828
some,
29+
toFileNameLowerCase,
2930
TypeAcquisition,
3031
Version,
3132
versionMajorMinor,
@@ -313,8 +314,8 @@ export function discoverTypings(
313314
// packages. So that needs this dance here.
314315
const pathComponents = getPathComponents(normalizePath(manifestPath));
315316
const isScoped = pathComponents[pathComponents.length - 3][0] === "@";
316-
return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar`
317-
!isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo`
317+
return isScoped && toFileNameLowerCase(pathComponents[pathComponents.length - 4]) === modulesDirName || // `node_modules/@foo/bar`
318+
!isScoped && toFileNameLowerCase(pathComponents[pathComponents.length - 3]) === modulesDirName; // `node_modules/foo`
318319
});
319320

320321
if (log) log(`Searching for typing names in ${packagesFolderPath}; all files: ${JSON.stringify(dependencyManifestNames)}`);
@@ -361,7 +362,7 @@ export function discoverTypings(
361362
const fromFileNames = mapDefined(fileNames, j => {
362363
if (!hasJSFileExtension(j)) return undefined;
363364

364-
const inferredTypingName = removeFileExtension(getBaseFileName(j.toLowerCase()));
365+
const inferredTypingName = removeFileExtension(toFileNameLowerCase(getBaseFileName(j)));
365366
const cleanedTypingName = removeMinAndVersionNumbers(inferredTypingName);
366367
return safeList.get(cleanedTypingName);
367368
});

0 commit comments

Comments
 (0)