Skip to content

Commit

Permalink
Merge branch 'main' into module-node20
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Jan 23, 2025
2 parents c947be2 + efe07a0 commit d119c3f
Show file tree
Hide file tree
Showing 221 changed files with 6,401 additions and 2,190 deletions.
5 changes: 1 addition & 4 deletions .github/codeql/codeql-configuration.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: CodeQL Configuration

paths:
- src
- scripts
- Herebyfile.mjs
paths-ignore:
- src/lib
- tests
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ jobs:
run: npm test -- --no-lint --coverage

- name: Upload coverage artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: coverage
path: coverage

- uses: codecov/codecov-action@7f8b4b4bde536c465e797be725718b88c5d95e0e # v5.1.1
- uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
with:
use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}
disable_search: true
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
- name: Upload baseline diff artifact
if: ${{ failure() && steps.check-baselines.conclusion == 'failure' }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: fix_baselines.patch
path: fix_baselines.patch
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
uses: github/codeql-action/init@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
with:
config-file: ./.github/codeql/codeql-configuration.yml
# Override language selection by uncommenting this and choosing your languages
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
uses: github/codeql-action/autobuild@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -70,4 +70,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
2 changes: 1 addition & 1 deletion .github/workflows/release-branch-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
npm pack ./
mv typescript-*.tgz typescript.tgz
- name: Upload built tarfile
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: tgz
path: typescript.tgz
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: 'Upload artifact'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: 'Upload to code-scanning'
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# TypeScript

[![GitHub Actions CI](https://github.com/microsoft/TypeScript/workflows/CI/badge.svg)](https://github.com/microsoft/TypeScript/actions?query=workflow%3ACI)
[![CI](https://github.com/microsoft/TypeScript/actions/workflows/ci.yml/badge.svg)](https://github.com/microsoft/TypeScript/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/typescript.svg)](https://www.npmjs.com/package/typescript)
[![Downloads](https://img.shields.io/npm/dm/typescript.svg)](https://www.npmjs.com/package/typescript)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/microsoft/TypeScript/badge)](https://securityscorecards.dev/viewer/?uri=github.com/microsoft/TypeScript)
Expand Down
3 changes: 3 additions & 0 deletions azure-pipelines.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ resources:
name: 1ESPipelineTemplates/1ESPipelineTemplates
ref: refs/tags/release

variables:
Codeql.InitParameters: '--codescanning-config=$(Build.SourcesDirectory)/.github/codeql/codeql-configuration.yml'

extends:
template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
parameters:
Expand Down
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export * from "../transformer.js";
export * from "../emitter.js";
export * from "../watchUtilities.js";
export * from "../program.js";
export * from "../programDiagnostics.js";
export * from "../builderStatePublic.js";
export * from "../builderState.js";
export * from "../builder.js";
Expand Down
13 changes: 9 additions & 4 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,9 +1318,11 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) ||
isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) ||
(isBooleanLiteral(expr.right) && isNarrowingExpression(expr.left) || isBooleanLiteral(expr.left) && isNarrowingExpression(expr.right));
const left = skipParentheses(expr.left);
const right = skipParentheses(expr.right);
return isNarrowableOperand(left) || isNarrowableOperand(right) ||
isNarrowingTypeofOperands(right, left) || isNarrowingTypeofOperands(left, right) ||
(isBooleanLiteral(right) && isNarrowingExpression(left) || isBooleanLiteral(left) && isNarrowingExpression(right));
case SyntaxKind.InstanceOfKeyword:
return isNarrowableOperand(expr.left);
case SyntaxKind.InKeyword:
Expand Down Expand Up @@ -1534,13 +1536,16 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
function bindForStatement(node: ForStatement): void {
const preLoopLabel = setContinueTarget(node, createLoopLabel());
const preBodyLabel = createBranchLabel();
const preIncrementorLabel = createBranchLabel();
const postLoopLabel = createBranchLabel();
bind(node.initializer);
addAntecedent(preLoopLabel, currentFlow);
currentFlow = preLoopLabel;
bindCondition(node.condition, preBodyLabel, postLoopLabel);
currentFlow = finishFlowLabel(preBodyLabel);
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
bindIterativeStatement(node.statement, postLoopLabel, preIncrementorLabel);
addAntecedent(preIncrementorLabel, currentFlow);
currentFlow = finishFlowLabel(preIncrementorLabel);
bind(node.incrementor);
addAntecedent(preLoopLabel, currentFlow);
currentFlow = finishFlowLabel(postLoopLabel);
Expand Down
12 changes: 9 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
getNumberLiteralType,
getBigIntType: () => bigintType,
getBigIntLiteralType,
getUnknownType: () => unknownType,
createPromiseType,
createArrayType,
getElementTypeOfArrayType,
Expand Down Expand Up @@ -6267,7 +6268,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return true;
}
if (requiresAddingUndefined && annotationType) {
annotationType = getOptionalType(annotationType, !isParameter(node));
annotationType = addOptionality(annotationType, !isParameter(node));
}
return !!annotationType && typeNodeIsEquivalentToType(node, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type);
},
Expand Down Expand Up @@ -16683,6 +16684,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case "Number":
checkNoTypeArguments(node);
return numberType;
case "BigInt":
checkNoTypeArguments(node);
return bigintType;
case "Boolean":
checkNoTypeArguments(node);
return booleanType;
Expand Down Expand Up @@ -27181,7 +27185,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return target.kind === SyntaxKind.SuperKeyword;
case SyntaxKind.NonNullExpression:
case SyntaxKind.ParenthesizedExpression:
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
case SyntaxKind.SatisfiesExpression:
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression | SatisfiesExpression).expression, target);
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
Expand Down Expand Up @@ -29533,7 +29538,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return narrowTypeByCallExpression(type, expr as CallExpression, assumeTrue);
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.NonNullExpression:
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression).expression, assumeTrue);
case SyntaxKind.SatisfiesExpression:
return narrowType(type, (expr as ParenthesizedExpression | NonNullExpression | SatisfiesExpression).expression, assumeTrue);
case SyntaxKind.BinaryExpression:
return narrowTypeByBinaryExpression(type, expr as BinaryExpression, assumeTrue);
case SyntaxKind.PrefixUnaryExpression:
Expand Down
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const libEntries: [string, string][] = [
["esnext.string", "lib.es2024.string.d.ts"],
["esnext.iterator", "lib.esnext.iterator.d.ts"],
["esnext.promise", "lib.esnext.promise.d.ts"],
["esnext.float16", "lib.esnext.float16.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],
];
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2989,7 +2989,7 @@ function loadModuleFromNearestNodeModulesDirectoryTypesScope(moduleName: string,
}

function loadModuleFromNearestNodeModulesDirectoryWorker(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, typesScopeOnly: boolean, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult<Resolved> {
const mode = state.features === 0 ? undefined : state.features & NodeResolutionFeatures.EsmMode ? ModuleKind.ESNext : ModuleKind.CommonJS;
const mode = state.features === 0 ? undefined : (state.features & NodeResolutionFeatures.EsmMode || state.conditions.includes("import")) ? ModuleKind.ESNext : ModuleKind.CommonJS;
// Do (up to) two passes through node_modules:
// 1. For each ancestor node_modules directory, try to find:
// i. TS/DTS files in the implementation package
Expand Down
1 change: 1 addition & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9536,6 +9536,7 @@ namespace Parser {
const node = factory.createExpressionWithTypeArguments(expression, typeArguments) as ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression; };
const res = finishNode(node, pos);
if (usedBrace) {
skipWhitespace();
parseExpected(SyntaxKind.CloseBraceToken);
}
return res;
Expand Down
112 changes: 106 additions & 6 deletions src/compiler/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,28 +624,128 @@ export function getNormalizedPathComponents(path: string, currentDirectory: stri
}

/** @internal */
export function getNormalizedAbsolutePath(fileName: string, currentDirectory: string | undefined): string {
return getPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
export function getNormalizedAbsolutePath(path: string, currentDirectory: string | undefined): string {
let rootLength = getRootLength(path);
if (rootLength === 0 && currentDirectory) {
path = combinePaths(currentDirectory, path);
rootLength = getRootLength(path);
}
else {
// combinePaths normalizes slashes, so not necessary in the other branch
path = normalizeSlashes(path);
}

const simpleNormalized = simpleNormalizePath(path);
if (simpleNormalized !== undefined) {
return simpleNormalized.length > rootLength ? removeTrailingDirectorySeparator(simpleNormalized) : simpleNormalized;
}

const length = path.length;
const root = path.substring(0, rootLength);
// `normalized` is only initialized once `path` is determined to be non-normalized
let normalized;
let index = rootLength;
let segmentStart = index;
let normalizedUpTo = index;
let seenNonDotDotSegment = rootLength !== 0;
while (index < length) {
// At beginning of segment
segmentStart = index;
let ch = path.charCodeAt(index);
while (ch === CharacterCodes.slash && index + 1 < length) {
index++;
ch = path.charCodeAt(index);
}
if (index > segmentStart) {
// Seen superfluous separator
normalized ??= path.substring(0, segmentStart - 1);
segmentStart = index;
}
// Past any superfluous separators
let segmentEnd = path.indexOf(directorySeparator, index + 1);
if (segmentEnd === -1) {
segmentEnd = length;
}
const segmentLength = segmentEnd - segmentStart;
if (segmentLength === 1 && path.charCodeAt(index) === CharacterCodes.dot) {
// "." segment (skip)
normalized ??= path.substring(0, normalizedUpTo);
}
else if (segmentLength === 2 && path.charCodeAt(index) === CharacterCodes.dot && path.charCodeAt(index + 1) === CharacterCodes.dot) {
// ".." segment
if (!seenNonDotDotSegment) {
if (normalized !== undefined) {
normalized += normalized.length === rootLength ? ".." : "/..";
}
else {
normalizedUpTo = index + 2;
}
}
else if (normalized === undefined) {
if (normalizedUpTo - 2 >= 0) {
normalized = path.substring(0, Math.max(rootLength, path.lastIndexOf(directorySeparator, normalizedUpTo - 2)));
}
else {
normalized = path.substring(0, normalizedUpTo);
}
}
else {
const lastSlash = normalized.lastIndexOf(directorySeparator);
if (lastSlash !== -1) {
normalized = normalized.substring(0, Math.max(rootLength, lastSlash));
}
else {
normalized = root;
}
if (normalized.length === rootLength) {
seenNonDotDotSegment = rootLength !== 0;
}
}
}
else if (normalized !== undefined) {
if (normalized.length !== rootLength) {
normalized += directorySeparator;
}
seenNonDotDotSegment = true;
normalized += path.substring(segmentStart, segmentEnd);
}
else {
seenNonDotDotSegment = true;
normalizedUpTo = segmentEnd;
}
index = segmentEnd + 1;
}
return normalized ?? (length > rootLength ? removeTrailingDirectorySeparator(path) : path);
}

/** @internal */
export function normalizePath(path: string): string {
path = normalizeSlashes(path);
let normalized = simpleNormalizePath(path);
if (normalized !== undefined) {
return normalized;
}
normalized = getNormalizedAbsolutePath(path, "");
return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
}

function simpleNormalizePath(path: string): string | undefined {
// Most paths don't require normalization
if (!relativePathSegmentRegExp.test(path)) {
return path;
}
// Some paths only require cleanup of `/./` or leading `./`
const simplified = path.replace(/\/\.\//g, "/").replace(/^\.\//, "");
let simplified = path.replace(/\/\.\//g, "/");
if (simplified.startsWith("./")) {
simplified = simplified.slice(2);
}
if (simplified !== path) {
path = simplified;
if (!relativePathSegmentRegExp.test(path)) {
return path;
}
}
// Other paths require full normalization
const normalized = getPathFromPathComponents(reducePathComponents(getPathComponents(path)));
return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
return undefined;
}

function getPathWithoutRoot(pathComponents: readonly string[]) {
Expand Down
Loading

0 comments on commit d119c3f

Please sign in to comment.