Skip to content

Commit

Permalink
Merge branch 'main' into fix21732
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/compiler/checker.ts
  • Loading branch information
ahejlsberg committed Sep 7, 2022
2 parents 335d7c8 + 3c3820b commit d178ea4
Show file tree
Hide file tree
Showing 451 changed files with 15,662 additions and 14,699 deletions.
13 changes: 13 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
/tests/**
/lib/**
/src/lib/*.generated.d.ts
# Ignore all compiled script outputs
/scripts/*.js
# But, not the ones that are hand-written.
# TODO: remove once scripts are pure JS
!/scripts/browserIntegrationTest.js
!/scripts/createPlaygroundBuild.js
!/scripts/failed-tests.js
!/scripts/find-unused-diagnostic-messages.js
!/scripts/lint-hooks.js
!/scripts/perf-result-post.js
!/scripts/post-vsts-artifact-comment.js
!/scripts/regenerate-unicode-identifier-parts.js
!/scripts/run-sequence.js
!/scripts/update-experimental-branches.js
/scripts/eslint/built/**
/internal/**
/coverage/**
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//
// ESLint in VS Code will lint any opened file (so long as it's not eslintignore'd), so
// that will work regardless of the below.
{ "files": ["*.ts"] }
{ "files": ["*.ts", "*.mts", "*.cts", "*.mjs", "*.cjs"] }
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- run: npm ci

- name: Linter
run: npm run lint:ci
run: npm run lint

browser-integration:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ const lint = eslint(".");
lint.displayName = "lint";
task("lint", lint);
task("lint").description = "Runs eslint on the compiler and scripts sources.";
task("lint").flags = {
" --ci": "Runs eslint additional rules",
};

const buildCancellationToken = () => buildProject("src/cancellationToken");
const cleanCancellationToken = () => cleanProject("src/cancellationToken");
Expand Down
331 changes: 110 additions & 221 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"mocha-fivemat-progress-reporter": "latest",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"prex": "^0.4.7",
"source-map-support": "latest",
"typescript": "^4.8.2",
"vinyl": "latest",
Expand All @@ -110,7 +109,6 @@
"clean": "gulp clean",
"gulp": "gulp",
"lint": "gulp lint",
"lint:ci": "gulp lint --ci",
"setup-hooks": "node scripts/link-hooks.js"
},
"browser": {
Expand Down
10 changes: 7 additions & 3 deletions scripts/build/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
const minimist = require("minimist");
const os = require("os");

const ci = ["1", "true"].includes(process.env.CI);

/** @type {CommandLineOptions} */
module.exports = minimist(process.argv.slice(2), {
boolean: ["dirty", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
boolean: ["dirty", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci"],
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
alias: {
/* eslint-disable quote-props */
Expand Down Expand Up @@ -33,12 +35,13 @@ module.exports = minimist(process.argv.slice(2), {
reporter: process.env.reporter || process.env.r,
lint: process.env.lint || true,
fix: process.env.fix || process.env.f,
workers: process.env.workerCount || ((os.cpus().length - (process.env.CI ? 0 : 1)) || 1),
workers: process.env.workerCount || ((os.cpus().length - (ci ? 0 : 1)) || 1),
failed: false,
keepFailed: false,
lkg: true,
dirty: false,
built: false
built: false,
ci,
}
});

Expand Down Expand Up @@ -67,6 +70,7 @@ if (module.exports.built) {
* @property {string|number} timeout
* @property {boolean} failed
* @property {boolean} keepFailed
* @property {boolean} ci
*
* @typedef {import("minimist").ParsedArgs & TypedOptions} CommandLineOptions
*/
Expand Down
15 changes: 5 additions & 10 deletions scripts/build/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require("path");
const mkdirP = require("mkdirp");
const log = require("fancy-log");
const cmdLineOptions = require("./options");
const { CancellationToken } = require("prex");
const { exec } = require("./utils");
const { findUpFile } = require("./findUpDir");

Expand All @@ -22,9 +21,8 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
* @param {string} defaultReporter
* @param {boolean} runInParallel
* @param {boolean} watchMode
* @param {import("prex").CancellationToken} [cancelToken]
*/
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode) {
let testTimeout = cmdLineOptions.timeout;
const tests = cmdLineOptions.tests;
const inspect = cmdLineOptions.break || cmdLineOptions.inspect;
Expand All @@ -38,7 +36,6 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
const shardId = +cmdLineOptions.shardId || undefined;
if (!cmdLineOptions.dirty) {
await cleanTestDirs();
cancelToken.throwIfCancellationRequested();
}

if (fs.existsSync(testConfigFile)) {
Expand Down Expand Up @@ -121,19 +118,17 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,

try {
setNodeEnvToDevelopment();
const { exitCode } = await exec(process.execPath, args, {
cancelToken,
});
const { exitCode } = await exec(process.execPath, args);
if (exitCode !== 0) {
errorStatus = exitCode;
error = new Error(`Process exited with status code ${errorStatus}.`);
}
else if (process.env.CI === "true") {
else if (cmdLineOptions.ci) {
// finally, do a sanity check and build the compiler with the built version of itself
log.info("Starting sanity check build...");
// Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"], { cancelToken });
const { exitCode } = await exec("gulp", ["local", "--lkg=false"], { cancelToken });
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
if (exitCode !== 0) {
errorStatus = exitCode;
error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
Expand Down
22 changes: 10 additions & 12 deletions scripts/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ts = require("../../lib/typescript");
const chalk = require("chalk");
const which = require("which");
const { spawn } = require("child_process");
const { CancellationToken, CancelError, Deferred } = require("prex");
const { Readable, Duplex } = require("stream");

/**
Expand All @@ -25,26 +24,17 @@ const { Readable, Duplex } = require("stream");
*
* @typedef ExecOptions
* @property {boolean} [ignoreExitCode]
* @property {import("prex").CancellationToken} [cancelToken]
* @property {boolean} [hidePrompt]
* @property {boolean} [waitForExit=true]
*/
async function exec(cmd, args, options = {}) {
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
const { ignoreExitCode, cancelToken = CancellationToken.none, waitForExit = true } = options;
cancelToken.throwIfCancellationRequested();
const { ignoreExitCode, waitForExit = true } = options;

if (!options.hidePrompt) log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
const proc = spawn(which.sync(cmd), args, { stdio: waitForExit ? "inherit" : "ignore" });
const registration = cancelToken.register(() => {
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
proc.kill("SIGINT");
proc.kill("SIGTERM");
reject(new CancelError());
});
if (waitForExit) {
proc.on("exit", exitCode => {
registration.unregister();
if (exitCode === 0 || ignoreExitCode) {
resolve({ exitCode });
}
Expand All @@ -53,7 +43,6 @@ async function exec(cmd, args, options = {}) {
}
});
proc.on("error", error => {
registration.unregister();
reject(error);
});
}
Expand Down Expand Up @@ -395,6 +384,15 @@ function rm(dest, opts) {
}
exports.rm = rm;

class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}

class Debouncer {
/**
* @param {number} timeout
Expand Down
4 changes: 2 additions & 2 deletions scripts/failed-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
}
}

const newOptions = Object.assign({}, options, { reporterOptions: reporterOptions.reporterOptions || {} });
const newOptions = { ...options, reporterOptions: reporterOptions.reporterOptions || {} };
if (reporterOptions.reporter === "xunit") {
newOptions.reporterOptions.output = "TEST-results.xml";
}
Expand Down Expand Up @@ -142,4 +142,4 @@ class FailedTestsReporter extends Mocha.reporters.Base {
}
}

module.exports = FailedTestsReporter;
module.exports = FailedTestsReporter;
3 changes: 2 additions & 1 deletion scripts/find-unused-diganostic-messages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ startOfDiags.split(EOL).forEach(line => {
try {
execSync(`grep -rnw 'src' -e 'Diagnostics.${diagName}'`).toString();
process.stdout.write(".");
} catch (error) {
}
catch (error) {
missingNames.push(diagName);
process.stdout.write("x");
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/post-vsts-artifact-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and then running \`npm install\`.

// Temporarily disable until we get access controls set up right
// Send a ping to https://github.com/microsoft/typescript-make-monaco-builds#pull-request-builds
await gh.request("POST /repos/microsoft/typescript-make-monaco-builds/dispatches", { event_type: process.env.SOURCE_ISSUE, headers: { Accept: "application/vnd.github.everest-preview+json" }});
await gh.request("POST /repos/microsoft/typescript-make-monaco-builds/dispatches", { event_type: process.env.SOURCE_ISSUE, headers: { Accept: "application/vnd.github.everest-preview+json" } });
}

main().catch(async e => {
Expand Down
3 changes: 1 addition & 2 deletions scripts/run-sequence.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check
const cp = require("child_process");
/**
*
* @param {[string, string[]][]} tasks
* @param {cp.SpawnSyncOptions} opts
*/
Expand All @@ -17,4 +16,4 @@ function runSequence(tasks, opts = { timeout: 100000, shell: true }) {
return lastResult && lastResult.stdout && lastResult.stdout.toString();
}

exports.runSequence = runSequence;
exports.runSequence = runSequence;
2 changes: 1 addition & 1 deletion scripts/update-experimental-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const triggeredPR = process.env.SOURCE_ISSUE || process.env.SYSTEM_PULLREQUEST_P
* This program should be invoked as `node ./scripts/update-experimental-branches <GithubAccessToken>`
* TODO: the following is racey - if two experiment-enlisted PRs trigger simultaneously and witness one another in an unupdated state, they'll both produce
* a new experimental branch, but each will be missing a change from the other. There's no _great_ way to fix this beyond setting the maximum concurrency
* of this task to 1 (so only one job is allowed to update experiments at a time).
* of this task to 1 (so only one job is allowed to update experiments at a time).
*/
async function main() {
const gh = new Octokit({
Expand Down
18 changes: 15 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25101,7 +25101,7 @@ namespace ts {
const narrowedPropType = narrowType(propType);
return filterType(type, t => {
const discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
return !(narrowedPropType.flags & TypeFlags.Never) && isTypeComparableTo(narrowedPropType, discriminantType);
return !(narrowedPropType.flags & TypeFlags.Never) && areTypesComparable(narrowedPropType, discriminantType);
});
}

Expand Down Expand Up @@ -25301,14 +25301,19 @@ namespace ts {
assumeTrue = !assumeTrue;
}
const valueType = getTypeOfExpression(value);
if ((type.flags & TypeFlags.Unknown) && assumeTrue && (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken)) {
if (((type.flags & TypeFlags.Unknown) || isEmptyAnonymousObjectType(type) && !(valueType.flags & TypeFlags.Nullable)) &&
assumeTrue &&
(operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken)
) {
if (valueType.flags & (TypeFlags.Primitive | TypeFlags.NonPrimitive)) {
return valueType;
}
if (valueType.flags & TypeFlags.Object) {
return nonPrimitiveType;
}
return type;
if (type.flags & TypeFlags.Unknown) {
return type;
}
}
if (valueType.flags & TypeFlags.Nullable) {
if (!strictNullChecks) {
Expand Down Expand Up @@ -28388,6 +28393,7 @@ namespace ts {
*/
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode | undefined) {
const attributes = openingLikeElement.attributes;
const attributesType = getContextualType(attributes, ContextFlags.None);
const allAttributesTable = strictNullChecks ? createSymbolTable() : undefined;
let attributesTable = createSymbolTable();
let spread: Type = emptyJsxObjectType;
Expand Down Expand Up @@ -28416,6 +28422,12 @@ namespace ts {
if (attributeDecl.name.escapedText === jsxChildrenPropertyName) {
explicitlySpecifyChildrenAttribute = true;
}
if (attributesType) {
const prop = getPropertyOfType(attributesType, member.escapedName);
if (prop && prop.declarations && isDeprecatedSymbol(prop)) {
addDeprecatedSuggestion(attributeDecl.name, prop.declarations, attributeDecl.name.escapedText as string);
}
}
}
else {
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3535,11 +3535,12 @@ namespace ts {
createDiagnosticForOptionName(Diagnostics.Option_preserveConstEnums_cannot_be_disabled_when_isolatedModules_is_enabled, "preserveConstEnums", "isolatedModules");
}

const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !isSourceFileJS(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON);
if (firstNonExternalModuleSourceFile) {
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length,
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(firstNonExternalModuleSourceFile.fileName)));
for (const file of files) {
if (!isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON) {
const span = getErrorSpanForNode(file, file);
programDiagnostics.add(createFileDiagnostic(file, span.start, span.length,
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(file.fileName)));
}
}
}
else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) {
Expand Down
Loading

0 comments on commit d178ea4

Please sign in to comment.