mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into prependWithBundleInfo
This commit is contained in:
@@ -16,7 +16,7 @@ Please fill in the *entire* template below.
|
||||
-->
|
||||
|
||||
<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
|
||||
**TypeScript Version:** 3.3.0-dev.201xxxxx
|
||||
**TypeScript Version:** 3.4.0-dev.201xxxxx
|
||||
|
||||
<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
|
||||
**Search Terms:**
|
||||
|
||||
+562
-543
File diff suppressed because it is too large
Load Diff
+2
-4
@@ -8,10 +8,8 @@ const path = require("path");
|
||||
const fold = require("travis-fold");
|
||||
const ts = require("./lib/typescript");
|
||||
const del = require("del");
|
||||
const getDirSize = require("./scripts/build/getDirSize");
|
||||
const { getDirSize, needsUpdate, flatten } = require("./scripts/build/utils");
|
||||
const { base64VLQFormatEncode } = require("./scripts/build/sourcemaps");
|
||||
const needsUpdate = require("./scripts/build/needsUpdate");
|
||||
const { flatten } = require("./scripts/build/project");
|
||||
|
||||
// add node_modules to path so we don't need global modules, prefer the modules by adding them first
|
||||
var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter;
|
||||
@@ -361,7 +359,7 @@ file(ConfigFileFor.tsserverLibrary, [], function () {
|
||||
compilerOptions: {
|
||||
"removeComments": false,
|
||||
"stripInternal": true,
|
||||
"declarationMap": false,
|
||||
"declaration": true,
|
||||
"outFile": "tsserverlibrary.out.js"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[](https://travis-ci.org/Microsoft/TypeScript)
|
||||
[](https://https://dev.azure.com/typescript/TypeScript/_build/latest?definitionId=4&view=logs)
|
||||
[](https://dev.azure.com/typescript/TypeScript/_build/latest?definitionId=4&view=logs)
|
||||
[](https://www.npmjs.com/package/typescript)
|
||||
[](https://www.npmjs.com/package/typescript)
|
||||
|
||||
|
||||
+3
-11
@@ -2,7 +2,7 @@
|
||||
"name": "typescript",
|
||||
"author": "Microsoft Corp.",
|
||||
"homepage": "https://www.typescriptlang.org/",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0",
|
||||
"license": "Apache-2.0",
|
||||
"description": "TypeScript is a language for application scale JavaScript development",
|
||||
"keywords": [
|
||||
@@ -35,10 +35,8 @@
|
||||
"@types/convert-source-map": "latest",
|
||||
"@types/del": "latest",
|
||||
"@types/glob": "latest",
|
||||
"@types/gulp": "3.X",
|
||||
"@types/gulp": "^4.0.5",
|
||||
"@types/gulp-concat": "latest",
|
||||
"@types/gulp-help": "latest",
|
||||
"@types/gulp-if": "0.0.33",
|
||||
"@types/gulp-newer": "latest",
|
||||
"@types/gulp-rename": "0.0.33",
|
||||
"@types/gulp-sourcemaps": "0.0.32",
|
||||
@@ -50,7 +48,6 @@
|
||||
"@types/mocha": "latest",
|
||||
"@types/node": "8.5.5",
|
||||
"@types/q": "latest",
|
||||
"@types/run-sequence": "latest",
|
||||
"@types/source-map-support": "latest",
|
||||
"@types/through2": "latest",
|
||||
"@types/travis-fold": "latest",
|
||||
@@ -63,16 +60,12 @@
|
||||
"del": "latest",
|
||||
"fancy-log": "latest",
|
||||
"fs-extra": "^6.0.1",
|
||||
"gulp": "3.X",
|
||||
"gulp-clone": "latest",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-concat": "latest",
|
||||
"gulp-help": "latest",
|
||||
"gulp-if": "latest",
|
||||
"gulp-insert": "latest",
|
||||
"gulp-newer": "latest",
|
||||
"gulp-rename": "latest",
|
||||
"gulp-sourcemaps": "latest",
|
||||
"gulp-typescript": "latest",
|
||||
"istanbul": "latest",
|
||||
"jake": "latest",
|
||||
"lodash": "4.17.10",
|
||||
@@ -86,7 +79,6 @@
|
||||
"prex": "^0.4.3",
|
||||
"q": "latest",
|
||||
"remove-internal": "^2.9.2",
|
||||
"run-sequence": "latest",
|
||||
"source-map-support": "latest",
|
||||
"through2": "latest",
|
||||
"travis-fold": "latest",
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// @ts-check
|
||||
const merge2 = require("merge2");
|
||||
const gulp = require("./gulp");
|
||||
const rename = require("gulp-rename");
|
||||
const rm = require("./rm");
|
||||
const { localBaseline, refBaseline } = require("./tests");
|
||||
|
||||
module.exports = baselineAccept;
|
||||
|
||||
function baselineAccept(subfolder = "") {
|
||||
return merge2(baselineCopy(subfolder), baselineDelete(subfolder));
|
||||
}
|
||||
|
||||
function baselineCopy(subfolder = "") {
|
||||
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline })
|
||||
.pipe(gulp.dest(refBaseline));
|
||||
}
|
||||
|
||||
function baselineDelete(subfolder = "") {
|
||||
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**/*.delete`], { base: localBaseline, read: false })
|
||||
.pipe(rm())
|
||||
.pipe(rename({ extname: "" }))
|
||||
.pipe(rm(refBaseline));
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
// @ts-check
|
||||
const browserify = require("browserify");
|
||||
const Vinyl = require("./vinyl");
|
||||
const Vinyl = require("vinyl");
|
||||
const { Transform } = require("stream");
|
||||
const { streamFromFile } = require("./utils");
|
||||
const { replaceContents } = require("./sourcemaps");
|
||||
|
||||
module.exports = browserifyFile;
|
||||
|
||||
/**
|
||||
* @param {import("browserify").Options} [opts]
|
||||
*/
|
||||
@@ -31,4 +29,5 @@ function browserifyFile(opts) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.browserify = browserifyFile;
|
||||
@@ -1,5 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
// this just fixes the incorrect types for chalk :/
|
||||
const chalk = /**@type {import("chalk").Chalk}*/(require("chalk").default || require("chalk"));
|
||||
module.exports = chalk;
|
||||
@@ -1,19 +0,0 @@
|
||||
// @ts-check
|
||||
const replace = require("./replace");
|
||||
|
||||
module.exports = exports = convertConstEnum;
|
||||
|
||||
/**
|
||||
* This regexp exists to capture our const enums and replace them with normal enums in our public API
|
||||
* - this is fine since we compile with preserveConstEnums, and ensures our consumers are not locked
|
||||
* to the TS version they compile with.
|
||||
*/
|
||||
const constEnumCaptureRegexp = /^(\s*)(export )?const enum (\S+) {(\s*)$/gm;
|
||||
const constEnumReplacement = "$1$2enum $3 {$4";
|
||||
|
||||
/**
|
||||
* Converts `const enum` declarations in a .d.ts file into non-const `enum` declarations.
|
||||
*/
|
||||
function convertConstEnum() {
|
||||
return replace(constEnumCaptureRegexp, constEnumReplacement);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// @ts-check
|
||||
module.exports = debounce;
|
||||
|
||||
/**
|
||||
* @param {() => void} cb
|
||||
* @param {number} timeout
|
||||
* @param {DebounceOptions} [opts]
|
||||
*
|
||||
* @typedef DebounceOptions
|
||||
* @property {number} [max]
|
||||
*/
|
||||
function debounce(cb, timeout, opts = {}) {
|
||||
if (timeout < 10) timeout = 10;
|
||||
let max = opts.max || 10;
|
||||
if (max < timeout) max = timeout;
|
||||
let minTimer;
|
||||
let maxTimer;
|
||||
return trigger;
|
||||
|
||||
function trigger() {
|
||||
if (max > timeout && !maxTimer) maxTimer = setTimeout(done, max);
|
||||
if (minTimer) clearTimeout(minTimer);
|
||||
minTimer = setTimeout(done, timeout);
|
||||
}
|
||||
|
||||
function done() {
|
||||
if (maxTimer) maxTimer = void clearTimeout(maxTimer);
|
||||
if (minTimer) minTimer = void clearTimeout(minTimer);
|
||||
cb();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// @ts-check
|
||||
const ts = require("../../lib/typescript");
|
||||
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
|
||||
|
||||
/** @type {FormatDiagnosticsHost} */
|
||||
const formatDiagnosticsHost = exports.formatDiagnosticsHost = {
|
||||
getCanonicalFileName: fileName => fileName,
|
||||
getCurrentDirectory: () => process.cwd(),
|
||||
getNewLine: () => ts.sys.newLine
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Diagnostic[]} diagnostics
|
||||
* @param {{ cwd?: string, pretty?: boolean }} [options]
|
||||
*/
|
||||
function formatDiagnostics(diagnostics, options) {
|
||||
return options && options.pretty
|
||||
? ts.formatDiagnosticsWithColorAndContext(diagnostics, getFormatDiagnosticsHost(options && options.cwd))
|
||||
: ts.formatDiagnostics(diagnostics, getFormatDiagnosticsHost(options && options.cwd));
|
||||
}
|
||||
exports.formatDiagnostics = formatDiagnostics;
|
||||
|
||||
/**
|
||||
* @param {Diagnostic[]} diagnostics
|
||||
* @param {{ cwd?: string }} [options]
|
||||
*/
|
||||
function reportDiagnostics(diagnostics, options) {
|
||||
log(formatDiagnostics(diagnostics, { cwd: options && options.cwd, pretty: process.stdout.isTTY }));
|
||||
}
|
||||
exports.reportDiagnostics = reportDiagnostics;
|
||||
|
||||
/**
|
||||
* @param {string | undefined} cwd
|
||||
* @returns {FormatDiagnosticsHost}
|
||||
*/
|
||||
function getFormatDiagnosticsHost(cwd) {
|
||||
if (!cwd || cwd === process.cwd()) return formatDiagnosticsHost;
|
||||
return {
|
||||
getCanonicalFileName: formatDiagnosticsHost.getCanonicalFileName,
|
||||
getCurrentDirectory: () => cwd,
|
||||
getNewLine: formatDiagnosticsHost.getNewLine
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {import("../../lib/typescript").FormatDiagnosticsHost} FormatDiagnosticsHost
|
||||
* @typedef {import("../../lib/typescript").Diagnostic} Diagnostic
|
||||
*/
|
||||
void 0;
|
||||
@@ -1,58 +0,0 @@
|
||||
// @ts-check
|
||||
const cp = require("child_process");
|
||||
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
|
||||
const isWin = /^win/.test(process.platform);
|
||||
const chalk = require("./chalk");
|
||||
const { CancellationToken, CancelError } = require("prex");
|
||||
|
||||
module.exports = exec;
|
||||
|
||||
/**
|
||||
* Executes the provided command once with the supplied arguments.
|
||||
* @param {string} cmd
|
||||
* @param {string[]} args
|
||||
* @param {ExecOptions} [options]
|
||||
*
|
||||
* @typedef ExecOptions
|
||||
* @property {boolean} [ignoreExitCode]
|
||||
* @property {import("prex").CancellationToken} [cancelToken]
|
||||
*/
|
||||
function exec(cmd, args, options = {}) {
|
||||
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
|
||||
const { ignoreExitCode, cancelToken = CancellationToken.none } = options;
|
||||
cancelToken.throwIfCancellationRequested();
|
||||
|
||||
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
|
||||
const subshellFlag = isWin ? "/c" : "-c";
|
||||
const command = isWin ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`];
|
||||
|
||||
log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
|
||||
const proc = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
|
||||
const registration = cancelToken.register(() => {
|
||||
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
|
||||
proc.kill("SIGINT");
|
||||
proc.kill("SIGTERM");
|
||||
reject(new CancelError());
|
||||
});
|
||||
proc.on("exit", exitCode => {
|
||||
registration.unregister();
|
||||
if (exitCode === 0 || ignoreExitCode) {
|
||||
resolve({ exitCode });
|
||||
}
|
||||
else {
|
||||
reject(new Error(`Process exited with code: ${exitCode}`));
|
||||
}
|
||||
});
|
||||
proc.on("error", error => {
|
||||
registration.unregister();
|
||||
reject(error);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} cmd
|
||||
*/
|
||||
function possiblyQuote(cmd) {
|
||||
return cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// @ts-check
|
||||
module.exports = finished;
|
||||
|
||||
/**
|
||||
* @param {NodeJS.ReadableStream | NodeJS.WritableStream} stream
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function finished(stream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const readable = "readable" in stream && stream.readable;
|
||||
const writable = "writable" in stream && stream.writable;
|
||||
|
||||
let countdown = 0;
|
||||
const cleanup = () => {
|
||||
if (readable) stream.removeListener("end", signal);
|
||||
if (writable) stream.removeListener("finish", signal);
|
||||
stream.removeListener("error", onerror);
|
||||
};
|
||||
const signal = () => {
|
||||
if (countdown > 0) {
|
||||
countdown--;
|
||||
if (countdown === 0) {
|
||||
cleanup();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
const onerror = (error) => {
|
||||
if (countdown > 0) {
|
||||
countdown = 0;
|
||||
cleanup();
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
stream.once("error", onerror);
|
||||
if (readable) {
|
||||
countdown++;
|
||||
stream.once("end", signal);
|
||||
}
|
||||
if (writable) {
|
||||
countdown++;
|
||||
stream.once("finish", signal);
|
||||
}
|
||||
if (countdown === 0) signal();
|
||||
});
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// @ts-check
|
||||
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
|
||||
module.exports = getDiffTool;
|
||||
|
||||
function getDiffTool() {
|
||||
const program = process.env.DIFF;
|
||||
if (!program) {
|
||||
log.warn("Add the 'DIFF' environment variable to the path of the program you want to use.");
|
||||
process.exit(1);
|
||||
}
|
||||
return program;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// @ts-check
|
||||
const { lstatSync, readdirSync } = require("fs");
|
||||
const { join } = require("path");
|
||||
|
||||
/**
|
||||
* Find the size of a directory recursively.
|
||||
* Symbolic links can cause a loop.
|
||||
* @param {string} root
|
||||
* @returns {number} bytes
|
||||
*/
|
||||
function getDirSize(root) {
|
||||
const stats = lstatSync(root);
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
return stats.size;
|
||||
}
|
||||
|
||||
return readdirSync(root)
|
||||
.map(file => getDirSize(join(root, file)))
|
||||
.reduce((acc, num) => acc + num, 0);
|
||||
}
|
||||
|
||||
module.exports = getDirSize;
|
||||
@@ -1,149 +0,0 @@
|
||||
// @ts-check
|
||||
const path = require("path");
|
||||
const child_process = require("child_process");
|
||||
const fs = require("fs");
|
||||
const tsc = require("gulp-typescript");
|
||||
const Vinyl = require("vinyl");
|
||||
const { Duplex, Readable } = require("stream");
|
||||
const protocol = require("./protocol");
|
||||
|
||||
/**
|
||||
* @param {string | undefined} tsConfigFileName
|
||||
* @param {tsc.Settings} settings
|
||||
* @param {CreateProjectOptions} options
|
||||
*
|
||||
* @typedef CreateProjectOptions
|
||||
* @property {string} [typescript]
|
||||
* @property {boolean} [parse]
|
||||
*/
|
||||
function createProject(tsConfigFileName, settings, options) {
|
||||
settings = Object.assign({}, settings);
|
||||
options = Object.assign({}, options);
|
||||
if (settings.typescript) throw new Error();
|
||||
|
||||
const localSettings = Object.assign({}, settings);
|
||||
if (options.typescript) {
|
||||
options.typescript = path.resolve(options.typescript);
|
||||
localSettings.typescript = require(options.typescript);
|
||||
}
|
||||
|
||||
const project = tsConfigFileName === undefined ? tsc.createProject(localSettings) : tsc.createProject(tsConfigFileName, localSettings);
|
||||
const wrappedProject = /** @type {tsc.Project} */((reporter = tsc.reporter.defaultReporter()) => {
|
||||
const ts = project.typescript;
|
||||
const proc = child_process.fork(require.resolve("./worker.js"), [], {
|
||||
// Prevent errors when debugging gulpfile due to the same debug port being passed to forked children.
|
||||
execArgv: []
|
||||
});
|
||||
/** @type {Map<string, import("vinyl")>} */
|
||||
const inputs = new Map();
|
||||
/** @type {Map<string, *>} */
|
||||
const sourceFiles = new Map();
|
||||
/** @type {protocol.SourceFileHost & protocol.VinylHost} */
|
||||
const host = {
|
||||
getVinyl(path) { return inputs.get(path); },
|
||||
getSourceFile(fileName) { return sourceFiles.get(fileName); },
|
||||
createSourceFile(fileName, text, languageVersion) {
|
||||
if (text === undefined) {
|
||||
text = fs.readFileSync(fileName, "utf8");
|
||||
}
|
||||
|
||||
/** @type {protocol.SourceFile} */
|
||||
let file;
|
||||
if (options.parse) {
|
||||
file = ts.createSourceFile(fileName, text, languageVersion, /*setParentNodes*/ true);
|
||||
}
|
||||
else {
|
||||
// NOTE: the built-in reporters in gulp-typescript don't actually need a full
|
||||
// source file, so save time by faking one unless requested.
|
||||
file = /**@type {protocol.SourceFile}*/({
|
||||
pos: 0,
|
||||
end: text.length,
|
||||
kind: ts.SyntaxKind.SourceFile,
|
||||
fileName,
|
||||
text,
|
||||
languageVersion,
|
||||
statements: /**@type {*} */([]),
|
||||
endOfFileToken: { pos: text.length, end: text.length, kind: ts.SyntaxKind.EndOfFileToken },
|
||||
amdDependencies: /**@type {*} */([]),
|
||||
referencedFiles: /**@type {*} */([]),
|
||||
typeReferenceDirectives: /**@type {*} */([]),
|
||||
libReferenceDirectives: /**@type {*} */([]),
|
||||
languageVariant: ts.LanguageVariant.Standard,
|
||||
isDeclarationFile: /\.d\.ts$/.test(fileName),
|
||||
hasNoDefaultLib: /[\\/]lib\.[^\\/]+\.d\.ts$/.test(fileName)
|
||||
});
|
||||
}
|
||||
sourceFiles.set(fileName, file);
|
||||
return file;
|
||||
}
|
||||
};
|
||||
/** @type {Duplex & { js?: Readable, dts?: Readable }} */
|
||||
const compileStream = new Duplex({
|
||||
objectMode: true,
|
||||
read() {},
|
||||
/** @param {*} file */
|
||||
write(file, _encoding, callback) {
|
||||
inputs.set(file.path, file);
|
||||
proc.send(protocol.message.write(file));
|
||||
callback();
|
||||
},
|
||||
final(callback) {
|
||||
proc.send(protocol.message.final());
|
||||
callback();
|
||||
}
|
||||
});
|
||||
const jsStream = compileStream.js = new Readable({
|
||||
objectMode: true,
|
||||
read() {}
|
||||
});
|
||||
const dtsStream = compileStream.dts = new Readable({
|
||||
objectMode: true,
|
||||
read() {}
|
||||
});
|
||||
proc.send(protocol.message.createProject(tsConfigFileName, settings, options));
|
||||
proc.on("message", (/**@type {protocol.WorkerMessage}*/ message) => {
|
||||
switch (message.method) {
|
||||
case "write": {
|
||||
const file = protocol.vinylFromJson(message.params);
|
||||
compileStream.push(file);
|
||||
if (file.path.endsWith(".d.ts")) {
|
||||
dtsStream.push(file);
|
||||
}
|
||||
else {
|
||||
jsStream.push(file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "final": {
|
||||
compileStream.push(null);
|
||||
jsStream.push(null);
|
||||
dtsStream.push(null);
|
||||
proc.kill(); // TODO(rbuckton): pool workers? may not be feasible due to gulp-typescript holding onto memory
|
||||
break;
|
||||
}
|
||||
case "error": {
|
||||
const error = protocol.errorFromJson(message.params);
|
||||
compileStream.emit("error", error);
|
||||
proc.kill(); // TODO(rbuckton): pool workers? may not be feasible due to gulp-typescript holding onto memory
|
||||
break;
|
||||
}
|
||||
case "reporter.error": {
|
||||
if (reporter.error) {
|
||||
const error = protocol.typeScriptErrorFromJson(message.params, host);
|
||||
reporter.error(error, project.typescript);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "reporter.finish": {
|
||||
if (reporter.finish) {
|
||||
reporter.finish(message.params);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return /** @type {*} */(compileStream);
|
||||
});
|
||||
return Object.assign(wrappedProject, project);
|
||||
}
|
||||
|
||||
exports.createProject = createProject;
|
||||
@@ -1,281 +0,0 @@
|
||||
// @ts-check
|
||||
const Vinyl = require("vinyl");
|
||||
|
||||
/**
|
||||
* @param {File} file
|
||||
* @returns {*}
|
||||
*/
|
||||
function vinylToJson(file) {
|
||||
if (file.isStream()) throw new TypeError("Streams not supported.");
|
||||
return {
|
||||
path: file.path,
|
||||
cwd: file.cwd,
|
||||
base: file.base,
|
||||
contents: file.isBuffer() ? file.contents.toString("utf8") : undefined,
|
||||
sourceMap: file.sourceMap
|
||||
};
|
||||
}
|
||||
exports.vinylToJson = vinylToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @returns {File}
|
||||
*/
|
||||
function vinylFromJson(json) {
|
||||
return new Vinyl({
|
||||
path: json.path,
|
||||
cwd: json.cwd,
|
||||
base: json.base,
|
||||
contents: typeof json.contents === "string" ? Buffer.from(json.contents, "utf8") : undefined,
|
||||
sourceMap: json.sourceMap
|
||||
});
|
||||
}
|
||||
exports.vinylFromJson = vinylFromJson;
|
||||
|
||||
/**
|
||||
* @param {Error} error
|
||||
* @returns {*}
|
||||
*/
|
||||
function errorToJson(error) {
|
||||
return {
|
||||
name: error.name,
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
};
|
||||
}
|
||||
exports.errorToJson = errorToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @returns {Error}
|
||||
*/
|
||||
function errorFromJson(json) {
|
||||
const error = new Error();
|
||||
error.name = json.name;
|
||||
error.message = json.message;
|
||||
error.stack = json.stack;
|
||||
return error;
|
||||
}
|
||||
exports.errorFromJson = errorFromJson;
|
||||
|
||||
/**
|
||||
* @param {TypeScriptError} error
|
||||
* @returns {*}
|
||||
*/
|
||||
function typeScriptErrorToJson(error) {
|
||||
return Object.assign({}, errorToJson(error), {
|
||||
fullFilename: error.fullFilename,
|
||||
relativeFilename: error.relativeFilename,
|
||||
file: error.file && { path: error.file.path },
|
||||
tsFile: error.tsFile && sourceFileToJson(error.tsFile),
|
||||
diagnostic: diagnosticToJson(error.diagnostic),
|
||||
startPosition: error.startPosition,
|
||||
endPosition: error.endPosition
|
||||
});
|
||||
}
|
||||
exports.typeScriptErrorToJson = typeScriptErrorToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @param {SourceFileHost & VinylHost} host
|
||||
* @returns {TypeScriptError}
|
||||
*/
|
||||
function typeScriptErrorFromJson(json, host) {
|
||||
const error = /**@type {TypeScriptError}*/(errorFromJson(json));
|
||||
error.fullFilename = json.fullFilename;
|
||||
error.relativeFilename = json.relativeFilename;
|
||||
error.file = json.file && host.getVinyl(json.file.path);
|
||||
error.tsFile = json.tsFile && sourceFileFromJson(json.tsFile, host);
|
||||
error.diagnostic = diagnosticFromJson(json.diagnostic, host);
|
||||
error.startPosition = json.startPosition;
|
||||
error.endPosition = json.endPosition;
|
||||
return error;
|
||||
}
|
||||
exports.typeScriptErrorFromJson = typeScriptErrorFromJson;
|
||||
|
||||
/**
|
||||
* @param {SourceFile} file
|
||||
* @returns {*}
|
||||
*/
|
||||
function sourceFileToJson(file) {
|
||||
return {
|
||||
fileName: file.fileName,
|
||||
text: file.text,
|
||||
languageVersion: file.languageVersion
|
||||
};
|
||||
}
|
||||
exports.sourceFileToJson = sourceFileToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @param {SourceFileHost} host
|
||||
*/
|
||||
function sourceFileFromJson(json, host) {
|
||||
return host.getSourceFile(json.fileName)
|
||||
|| host.createSourceFile(json.fileName, json.text, json.languageVersion);
|
||||
}
|
||||
exports.sourceFileFromJson = sourceFileFromJson;
|
||||
|
||||
/**
|
||||
* @param {Diagnostic} diagnostic
|
||||
* @returns {*}
|
||||
*/
|
||||
function diagnosticToJson(diagnostic) {
|
||||
return Object.assign({}, diagnosticRelatedInformationToJson(diagnostic), {
|
||||
category: diagnostic.category,
|
||||
code: diagnostic.code,
|
||||
source: diagnostic.source,
|
||||
relatedInformation: diagnostic.relatedInformation && diagnostic.relatedInformation.map(diagnosticRelatedInformationToJson)
|
||||
});
|
||||
}
|
||||
exports.diagnosticToJson = diagnosticToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @param {SourceFileHost} host
|
||||
* @returns {Diagnostic}
|
||||
*/
|
||||
function diagnosticFromJson(json, host) {
|
||||
return Object.assign({}, diagnosticRelatedInformationFromJson(json, host), {
|
||||
category: json.category,
|
||||
code: json.code,
|
||||
source: json.source,
|
||||
relatedInformation: json.relatedInformation && json.relatedInformation.map(json => diagnosticRelatedInformationFromJson(json, host))
|
||||
});
|
||||
}
|
||||
exports.diagnosticFromJson = diagnosticFromJson;
|
||||
|
||||
/**
|
||||
* @param {DiagnosticRelatedInformation} diagnostic
|
||||
* @returns {*}
|
||||
*/
|
||||
function diagnosticRelatedInformationToJson(diagnostic) {
|
||||
return {
|
||||
file: diagnostic.file && { fileName: diagnostic.file.fileName },
|
||||
start: diagnostic.start,
|
||||
length: diagnostic.length,
|
||||
messageText: diagnostic.messageText
|
||||
};
|
||||
}
|
||||
exports.diagnosticRelatedInformationToJson = diagnosticRelatedInformationToJson;
|
||||
|
||||
/**
|
||||
* @param {*} json
|
||||
* @param {SourceFileHost} host
|
||||
* @returns {DiagnosticRelatedInformation}
|
||||
*/
|
||||
function diagnosticRelatedInformationFromJson(json, host) {
|
||||
return {
|
||||
file: json.file && sourceFileFromJson(json.file, host),
|
||||
start: json.start,
|
||||
length: json.length,
|
||||
messageText: json.messageText,
|
||||
category: json.category,
|
||||
code: json.code
|
||||
};
|
||||
}
|
||||
exports.diagnosticRelatedInformationFromJson = diagnosticRelatedInformationFromJson;
|
||||
|
||||
exports.message = {};
|
||||
|
||||
/**
|
||||
* @param {string | undefined} tsConfigFileName
|
||||
* @param {import("gulp-typescript").Settings} settings
|
||||
* @param {Object} options
|
||||
* @param {string} [options.typescript]
|
||||
* @returns {CreateProjectMessage}
|
||||
*
|
||||
* @typedef CreateProjectMessage
|
||||
* @property {"createProject"} method
|
||||
* @property {CreateProjectParams} params
|
||||
*
|
||||
* @typedef CreateProjectParams
|
||||
* @property {string | undefined} tsConfigFileName
|
||||
* @property {import("gulp-typescript").Settings} settings
|
||||
* @property {CreateProjectOptions} options
|
||||
*
|
||||
* @typedef CreateProjectOptions
|
||||
* @property {string} [typescript]
|
||||
*/
|
||||
exports.message.createProject = function(tsConfigFileName, settings, options) {
|
||||
return { method: "createProject", params: { tsConfigFileName, settings, options } };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {File} file
|
||||
* @returns {WriteMessage}
|
||||
*
|
||||
* @typedef WriteMessage
|
||||
* @property {"write"} method
|
||||
* @property {*} params
|
||||
*/
|
||||
exports.message.write = function(file) {
|
||||
return { method: "write", params: vinylToJson(file) };
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {FinalMessage}
|
||||
*
|
||||
* @typedef FinalMessage
|
||||
* @property {"final"} method
|
||||
*/
|
||||
exports.message.final = function() {
|
||||
return { method: "final" };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Error} error
|
||||
* @returns {ErrorMessage}
|
||||
*
|
||||
* @typedef ErrorMessage
|
||||
* @property {"error"} method
|
||||
* @property {*} params
|
||||
*/
|
||||
exports.message.error = function(error) {
|
||||
return { method: "error", params: errorToJson(error) };
|
||||
};
|
||||
|
||||
exports.message.reporter = {};
|
||||
|
||||
/**
|
||||
* @param {TypeScriptError} error
|
||||
* @returns {reporter.ErrorMessage}
|
||||
*
|
||||
* @typedef reporter.ErrorMessage
|
||||
* @property {"reporter.error"} method
|
||||
* @property {*} params
|
||||
*/
|
||||
exports.message.reporter.error = function(error) {
|
||||
return { method: "reporter.error", params: typeScriptErrorToJson(error) };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {*} results
|
||||
* @returns {reporter.FinishMessage}
|
||||
*
|
||||
* @typedef reporter.FinishMessage
|
||||
* @property {"reporter.finish"} method
|
||||
* @property {*} params
|
||||
*/
|
||||
exports.message.reporter.finish = function(results) {
|
||||
return { method: "reporter.finish", params: results };
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {import("vinyl")} File
|
||||
* @typedef {typeof import("typescript")} TypeScriptModule
|
||||
* @typedef {import("typescript").SourceFile} SourceFile
|
||||
* @typedef {import("typescript").Diagnostic} Diagnostic
|
||||
* @typedef {import("typescript").DiagnosticRelatedInformation} DiagnosticRelatedInformation
|
||||
* @typedef {import("gulp-typescript").reporter.TypeScriptError} TypeScriptError
|
||||
* @typedef {WriteMessage | FinalMessage | CreateProjectMessage} HostMessage
|
||||
* @typedef {WriteMessage | FinalMessage | ErrorMessage | reporter.ErrorMessage | reporter.FinishMessage} WorkerMessage
|
||||
*
|
||||
* @typedef SourceFileHost
|
||||
* @property {(fileName: string) => SourceFile | undefined} getSourceFile
|
||||
* @property {(fileName: string, text: string, languageVersion: number) => SourceFile} createSourceFile
|
||||
*
|
||||
* @typedef VinylHost
|
||||
* @property {(path: string) => File | undefined} getVinyl
|
||||
*/
|
||||
void 0;
|
||||
@@ -1,79 +0,0 @@
|
||||
// @ts-check
|
||||
const fs = require("fs");
|
||||
const tsc = require("gulp-typescript");
|
||||
const { Readable, Writable } = require("stream");
|
||||
const protocol = require("./protocol");
|
||||
|
||||
/** @type {tsc.Project} */
|
||||
let project;
|
||||
|
||||
/** @type {Readable} */
|
||||
let inputStream;
|
||||
|
||||
/** @type {Writable} */
|
||||
let outputStream;
|
||||
|
||||
/** @type {tsc.CompileStream} */
|
||||
let compileStream;
|
||||
|
||||
process.on("message", (/**@type {protocol.HostMessage}*/ message) => {
|
||||
try {
|
||||
switch (message.method) {
|
||||
case "createProject": {
|
||||
const { tsConfigFileName, settings, options } = message.params;
|
||||
if (options.typescript) {
|
||||
settings.typescript = require(options.typescript);
|
||||
}
|
||||
|
||||
project = tsConfigFileName === undefined
|
||||
? tsc.createProject(settings)
|
||||
: tsc.createProject(tsConfigFileName, settings);
|
||||
|
||||
inputStream = new Readable({
|
||||
objectMode: true,
|
||||
read() {}
|
||||
});
|
||||
|
||||
outputStream = new Writable({
|
||||
objectMode: true,
|
||||
/**
|
||||
* @param {*} file
|
||||
*/
|
||||
write(file, _, callback) {
|
||||
process.send(protocol.message.write(file));
|
||||
callback();
|
||||
},
|
||||
final(callback) {
|
||||
process.send(protocol.message.final());
|
||||
callback();
|
||||
}
|
||||
});
|
||||
compileStream = project({
|
||||
error(error) { process.send(protocol.message.reporter.error(error)); },
|
||||
finish(results) { process.send(protocol.message.reporter.finish(results)); }
|
||||
});
|
||||
compileStream.on("error", error => {
|
||||
process.send(protocol.message.error(error));
|
||||
});
|
||||
outputStream.on("error", () => {
|
||||
/* do nothing */
|
||||
});
|
||||
inputStream.pipe(compileStream).pipe(outputStream);
|
||||
break;
|
||||
}
|
||||
case "write": {
|
||||
const file = protocol.vinylFromJson(message.params);
|
||||
if (!file.isBuffer()) file.contents = fs.readFileSync(file.path);
|
||||
inputStream.push(file);
|
||||
break;
|
||||
}
|
||||
case "final": {
|
||||
inputStream.push(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
process.send(protocol.message.error(e));
|
||||
}
|
||||
});
|
||||
@@ -1,8 +0,0 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @typedef {import("gulp").Gulp} Gulp
|
||||
* @typedef {import("gulp-help").GulpHelp} GulpHelp
|
||||
* @typedef {GulpHelp & { Gulp: new () => Gulp }} DotGulpModule
|
||||
* @type {DotGulpModule}
|
||||
*/
|
||||
module.exports = require("gulp-help")(require("gulp"));
|
||||
@@ -1,30 +0,0 @@
|
||||
// @ts-check
|
||||
const readJson = require("./readJson");
|
||||
const path = require("path");
|
||||
const gulp = require("./gulp");
|
||||
const newer = require("gulp-newer");
|
||||
const concat = require("gulp-concat");
|
||||
const merge2 = require("merge2");
|
||||
|
||||
/** @type {{ libs: string[], paths?: Record<string, string>, sources?: Record<string, string[]> }} */
|
||||
const libraries = readJson("./src/lib/libs.json");
|
||||
const libs = libraries.libs.map(lib => {
|
||||
const relativeSources = ["header.d.ts"].concat(libraries.sources && libraries.sources[lib] || [lib + ".d.ts"]);
|
||||
const relativeTarget = libraries.paths && libraries.paths[lib] || ("lib." + lib + ".d.ts");
|
||||
const sources = relativeSources.map(s => path.posix.join("src/lib", s));
|
||||
const target = `built/local/${relativeTarget}`;
|
||||
return { target, relativeTarget, sources };
|
||||
});
|
||||
exports.libraryTargets = libs.map(lib => lib.target);
|
||||
|
||||
/**
|
||||
* @param {string[]} prepends
|
||||
*/
|
||||
function generateLibs(prepends) {
|
||||
return merge2(libs.map(({ sources, target, relativeTarget }) =>
|
||||
gulp.src(prepends.concat(sources))
|
||||
.pipe(newer(target))
|
||||
.pipe(concat(relativeTarget, { newLine: "\n\n" }))
|
||||
.pipe(gulp.dest("built/local"))));
|
||||
}
|
||||
exports.generateLibs = generateLibs;
|
||||
@@ -1,14 +0,0 @@
|
||||
// @ts-check
|
||||
const mkdirp = require("mkdirp");
|
||||
|
||||
module.exports = exports = mkdirpAsync;
|
||||
|
||||
/**
|
||||
* @param {string} dir
|
||||
* @param {mkdirp.Mode | mkdirp.Options} [opts]
|
||||
*/
|
||||
function mkdirpAsync(dir, opts) {
|
||||
return new Promise((resolve, reject) => mkdirp(dir, opts, (err, made) => err ? reject(err) : resolve(made)));
|
||||
}
|
||||
|
||||
exports.sync = mkdirp.sync;
|
||||
@@ -1,72 +0,0 @@
|
||||
// @ts-check
|
||||
const fs = require("fs");
|
||||
|
||||
module.exports = needsUpdate;
|
||||
|
||||
/**
|
||||
* @param {string | string[]} source
|
||||
* @param {string | string[]} dest
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function needsUpdate(source, dest) {
|
||||
if (typeof source === "string" && typeof dest === "string") {
|
||||
if (fs.existsSync(dest)) {
|
||||
const {mtime: outTime} = fs.statSync(dest);
|
||||
const {mtime: inTime} = fs.statSync(source);
|
||||
if (+inTime <= +outTime) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof source === "string" && typeof dest !== "string") {
|
||||
const {mtime: inTime} = fs.statSync(source);
|
||||
for (const filepath of dest) {
|
||||
if (fs.existsSync(filepath)) {
|
||||
const {mtime: outTime} = fs.statSync(filepath);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (typeof source !== "string" && typeof dest === "string") {
|
||||
if (fs.existsSync(dest)) {
|
||||
const {mtime: outTime} = fs.statSync(dest);
|
||||
for (const filepath of source) {
|
||||
if (fs.existsSync(filepath)) {
|
||||
const {mtime: inTime} = fs.statSync(filepath);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (typeof source !== "string" && typeof dest !== "string") {
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
if (!dest[i]) {
|
||||
continue;
|
||||
}
|
||||
if (fs.existsSync(dest[i])) {
|
||||
const {mtime: outTime} = fs.statSync(dest[i]);
|
||||
const {mtime: inTime} = fs.statSync(source[i]);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ const os = require("os");
|
||||
|
||||
/** @type {CommandLineOptions} */
|
||||
module.exports = minimist(process.argv.slice(2), {
|
||||
boolean: ["debug", "dirty", "inspect", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed"],
|
||||
boolean: ["debug", "dirty", "inspect", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
|
||||
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
|
||||
alias: {
|
||||
"b": "browser",
|
||||
@@ -15,7 +15,7 @@ module.exports = minimist(process.argv.slice(2), {
|
||||
"r": "reporter",
|
||||
"c": "colors", "color": "colors",
|
||||
"w": "workers",
|
||||
"f": "fix",
|
||||
"f": "fix"
|
||||
},
|
||||
default: {
|
||||
soft: false,
|
||||
@@ -35,10 +35,15 @@ module.exports = minimist(process.argv.slice(2), {
|
||||
failed: false,
|
||||
keepFailed: false,
|
||||
lkg: true,
|
||||
dirty: false
|
||||
dirty: false,
|
||||
built: false
|
||||
}
|
||||
});
|
||||
|
||||
if (module.exports.built) {
|
||||
module.exports.lkg = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef TypedOptions
|
||||
* @property {boolean} debug
|
||||
@@ -48,6 +53,7 @@ module.exports = minimist(process.argv.slice(2), {
|
||||
* @property {boolean} colors
|
||||
* @property {boolean} lint
|
||||
* @property {boolean} lkg
|
||||
* @property {boolean} built
|
||||
* @property {boolean} soft
|
||||
* @property {boolean} fix
|
||||
* @property {string} browser
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
// @ts-check
|
||||
const stream = require("stream");
|
||||
const Vinyl = require("./vinyl");
|
||||
const Vinyl = require("vinyl");
|
||||
const ts = require("../../lib/typescript");
|
||||
const fs = require("fs");
|
||||
const { base64VLQFormatEncode } = require("./sourcemaps");
|
||||
|
||||
module.exports = exports = prepend;
|
||||
|
||||
/**
|
||||
* @param {string | ((file: Vinyl) => string)} data
|
||||
* @param {string | ((file: import("vinyl")) => string)} data
|
||||
*/
|
||||
function prepend(data) {
|
||||
return new stream.Transform({
|
||||
objectMode: true,
|
||||
/**
|
||||
* @param {string | Buffer | Vinyl} input
|
||||
* @param {string | Buffer | import("vinyl")} input
|
||||
* @param {(error: Error, data?: any) => void} cb
|
||||
*/
|
||||
transform(input, _, cb) {
|
||||
@@ -56,11 +54,11 @@ function prepend(data) {
|
||||
exports.prepend = prepend;
|
||||
|
||||
/**
|
||||
* @param {string | ((file: Vinyl) => string)} file
|
||||
* @param {string | ((file: import("vinyl")) => string)} file
|
||||
*/
|
||||
function prependFile(file) {
|
||||
const data = typeof file === "string" ? fs.readFileSync(file, "utf8") :
|
||||
vinyl => fs.readFileSync(file(vinyl), "utf8");
|
||||
return prepend(data)
|
||||
}
|
||||
exports.file = prependFile;
|
||||
exports.prependFile = prependFile;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
// @ts-check
|
||||
const { exec, Debouncer } = require("./utils");
|
||||
|
||||
class ProjectQueue {
|
||||
/**
|
||||
* @param {(projects: string[], lkg: boolean, force: boolean) => Promise<any>} action
|
||||
*/
|
||||
constructor(action) {
|
||||
/** @type {{ lkg: boolean, force: boolean, projects?: string[], debouncer: Debouncer }[]} */
|
||||
this._debouncers = [];
|
||||
this._action = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} project
|
||||
* @param {object} options
|
||||
*/
|
||||
enqueue(project, { lkg = true, force = false } = {}) {
|
||||
let entry = this._debouncers.find(entry => entry.lkg === lkg && entry.force === force);
|
||||
if (!entry) {
|
||||
const debouncer = new Debouncer(100, async () => {
|
||||
const projects = entry.projects;
|
||||
if (projects) {
|
||||
entry.projects = undefined;
|
||||
await this._action(projects, lkg, force);
|
||||
}
|
||||
});
|
||||
this._debouncers.push(entry = { lkg, force, debouncer });
|
||||
}
|
||||
if (!entry.projects) entry.projects = [];
|
||||
entry.projects.push(project);
|
||||
return entry.debouncer.enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
const projectBuilder = new ProjectQueue((projects, lkg, force) => exec(process.execPath, [lkg ? "./lib/tsc" : "./built/local/tsc", "-b", ...(force ? ["--force"] : []), ...projects], { hidePrompt: true }));
|
||||
|
||||
/**
|
||||
* @param {string} project
|
||||
* @param {object} [options]
|
||||
* @param {boolean} [options.lkg=true]
|
||||
* @param {boolean} [options.force=false]
|
||||
*/
|
||||
exports.buildProject = (project, { lkg, force } = {}) => projectBuilder.enqueue(project, { lkg, force });
|
||||
|
||||
const projectCleaner = new ProjectQueue((projects, lkg) => exec(process.execPath, [lkg ? "./lib/tsc" : "./built/local/tsc", "-b", "--clean", ...projects], { hidePrompt: true }));
|
||||
|
||||
/**
|
||||
* @param {string} project
|
||||
*/
|
||||
exports.cleanProject = (project) => projectCleaner.enqueue(project);
|
||||
|
||||
const projectWatcher = new ProjectQueue((projects) => exec(process.execPath, ["./lib/tsc", "-b", "--watch", ...projects], { hidePrompt: true }));
|
||||
|
||||
/**
|
||||
* @param {string} project
|
||||
* @param {object} [options]
|
||||
* @param {boolean} [options.lkg=true]
|
||||
*/
|
||||
exports.watchProject = (project, { lkg } = {}) => projectWatcher.enqueue(project, { lkg });
|
||||
@@ -1,17 +0,0 @@
|
||||
// @ts-check
|
||||
const ts = require("../../lib/typescript");
|
||||
const fs = require("fs");
|
||||
const { reportDiagnostics } = require("./diagnostics");
|
||||
|
||||
module.exports = exports = readJson;
|
||||
|
||||
/** @param {string} jsonPath */
|
||||
function readJson(jsonPath) {
|
||||
const jsonText = fs.readFileSync(jsonPath, "utf8");
|
||||
const result = ts.parseConfigFileTextToJson(jsonPath, jsonText);
|
||||
if (result.error) {
|
||||
reportDiagnostics([result.error]);
|
||||
throw new Error("An error occurred during parse.");
|
||||
}
|
||||
return result.config;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// @ts-check
|
||||
const insert = require("gulp-insert");
|
||||
|
||||
/**
|
||||
* @param {string | RegExp} searchValue
|
||||
* @param {string | ((...args: string[]) => string)} replacer
|
||||
*/
|
||||
function replace(searchValue, replacer) {
|
||||
return insert.transform(content => content.replace(searchValue, /**@type {string}*/(replacer)));
|
||||
}
|
||||
|
||||
module.exports = replace;
|
||||
@@ -1,84 +0,0 @@
|
||||
// @ts-check
|
||||
const { Duplex } = require("stream");
|
||||
const path = require("path");
|
||||
const Vinyl = require("vinyl");
|
||||
const del = require("del");
|
||||
|
||||
module.exports = rm;
|
||||
|
||||
/**
|
||||
* @param {string | ((file: File) => string) | Options} [dest]
|
||||
* @param {Options} [opts]
|
||||
*/
|
||||
function rm(dest, opts) {
|
||||
if (dest && typeof dest === "object") opts = dest, dest = undefined;
|
||||
let failed = false;
|
||||
|
||||
const cwd = path.resolve(opts && opts.cwd || process.cwd());
|
||||
|
||||
/** @type {{ file: File, deleted: boolean, promise: Promise<any>, cb: Function }[]} */
|
||||
const pending = [];
|
||||
|
||||
const processDeleted = () => {
|
||||
if (failed) return;
|
||||
while (pending.length && pending[0].deleted) {
|
||||
const { file, cb } = pending.shift();
|
||||
duplex.push(file);
|
||||
cb();
|
||||
}
|
||||
};
|
||||
|
||||
const duplex = new Duplex({
|
||||
objectMode: true,
|
||||
/**
|
||||
* @param {string|Buffer|File} file
|
||||
*/
|
||||
write(file, _, cb) {
|
||||
if (failed) return;
|
||||
if (typeof file === "string" || Buffer.isBuffer(file)) return cb(new Error("Only Vinyl files are supported."));
|
||||
const basePath = typeof dest === "string" ? path.resolve(cwd, dest) :
|
||||
typeof dest === "function" ? path.resolve(cwd, dest(file)) :
|
||||
file.base;
|
||||
const filePath = path.resolve(basePath, file.relative);
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
file.path = filePath;
|
||||
const entry = {
|
||||
file,
|
||||
deleted: false,
|
||||
cb,
|
||||
promise: del(file.path).then(() => {
|
||||
entry.deleted = true;
|
||||
processDeleted();
|
||||
}, err => {
|
||||
failed = true;
|
||||
pending.length = 0;
|
||||
cb(err);
|
||||
})
|
||||
};
|
||||
pending.push(entry);
|
||||
},
|
||||
final(cb) {
|
||||
processDeleted();
|
||||
if (pending.length) {
|
||||
Promise
|
||||
.all(pending.map(entry => entry.promise))
|
||||
.then(() => processDeleted())
|
||||
.then(() => cb(), cb);
|
||||
return;
|
||||
}
|
||||
cb();
|
||||
},
|
||||
read() {
|
||||
}
|
||||
});
|
||||
return duplex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {import("vinyl")} File
|
||||
*
|
||||
* @typedef Options
|
||||
* @property {string} [cwd]
|
||||
*/
|
||||
void 0;
|
||||
@@ -1,12 +1,13 @@
|
||||
// @ts-check
|
||||
/// <reference path="../types/ambient.d.ts" />
|
||||
|
||||
const path = require("path");
|
||||
const Vinyl = require("./vinyl");
|
||||
const convertMap = require("convert-source-map");
|
||||
const applySourceMap = require("vinyl-sourcemaps-apply");
|
||||
const through2 = require("through2");
|
||||
|
||||
/**
|
||||
* @param {Vinyl} input
|
||||
* @param {import("vinyl")} input
|
||||
* @param {string | Buffer} contents
|
||||
* @param {string | RawSourceMap} [sourceMap]
|
||||
*/
|
||||
@@ -16,13 +17,13 @@ function replaceContents(input, contents, sourceMap) {
|
||||
if (input.sourceMap) {
|
||||
output.sourceMap = typeof input.sourceMap === "string" ? /**@type {RawSourceMap}*/(JSON.parse(input.sourceMap)) : input.sourceMap;
|
||||
if (typeof sourceMap === "string") {
|
||||
sourceMap = /**@type {RawSourceMap}*/(JSON.parse(sourceMap));
|
||||
sourceMap = /** @type {RawSourceMap} */(JSON.parse(sourceMap));
|
||||
}
|
||||
else if (sourceMap === undefined) {
|
||||
const stringContents = typeof contents === "string" ? contents : contents.toString("utf8");
|
||||
const newSourceMapConverter = convertMap.fromSource(stringContents);
|
||||
if (newSourceMapConverter) {
|
||||
sourceMap = /**@type {RawSourceMap}*/(newSourceMapConverter.toObject());
|
||||
sourceMap = /** @type {RawSourceMap} */(newSourceMapConverter.toObject());
|
||||
output.contents = new Buffer(convertMap.removeMapFileComments(stringContents), "utf8");
|
||||
}
|
||||
}
|
||||
@@ -31,7 +32,7 @@ function replaceContents(input, contents, sourceMap) {
|
||||
const base = input.base || cwd;
|
||||
const sourceRoot = output.sourceMap.sourceRoot;
|
||||
makeAbsoluteSourceMap(cwd, base, output.sourceMap);
|
||||
makeAbsoluteSourceMap(cwd, base, sourceMap);
|
||||
makeAbsoluteSourceMap(cwd, base, /** @type {RawSourceMap} */(sourceMap));
|
||||
applySourceMap(output, sourceMap);
|
||||
makeRelativeSourceMap(cwd, base, sourceRoot, output.sourceMap);
|
||||
}
|
||||
@@ -44,10 +45,12 @@ function replaceContents(input, contents, sourceMap) {
|
||||
exports.replaceContents = replaceContents;
|
||||
|
||||
function removeSourceMaps() {
|
||||
return through2.obj((/**@type {Vinyl}*/file, _, cb) => {
|
||||
if (file.sourceMap && file.isBuffer()) {
|
||||
return through2.obj((/**@type {import("vinyl")}*/file, _, cb) => {
|
||||
if (file.isBuffer()) {
|
||||
file.contents = Buffer.from(convertMap.removeMapFileComments(file.contents.toString("utf8")), "utf8");
|
||||
file.sourceMap = undefined;
|
||||
if (file.sourceMap) {
|
||||
file.sourceMap = undefined;
|
||||
}
|
||||
}
|
||||
cb(null, file);
|
||||
});
|
||||
@@ -59,7 +62,7 @@ exports.removeSourceMaps = removeSourceMaps;
|
||||
* @param {string | undefined} base
|
||||
* @param {RawSourceMap} sourceMap
|
||||
*
|
||||
* @typedef RawSourceMap
|
||||
* @typedef {object} RawSourceMap
|
||||
* @property {string} version
|
||||
* @property {string} file
|
||||
* @property {string} [sourceRoot]
|
||||
|
||||
+9
-13
@@ -1,16 +1,16 @@
|
||||
// @ts-check
|
||||
const gulp = require("./gulp");
|
||||
const gulp = require("gulp");
|
||||
const del = require("del");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const mkdirP = require("./mkdirp");
|
||||
const mkdirP = require("mkdirp");
|
||||
const log = require("fancy-log");
|
||||
const cmdLineOptions = require("./options");
|
||||
const exec = require("./exec");
|
||||
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
|
||||
const { CancellationToken } = require("prex");
|
||||
const mochaJs = require.resolve("mocha/bin/_mocha");
|
||||
const { exec } = require("./utils");
|
||||
|
||||
const mochaJs = require.resolve("mocha/bin/_mocha");
|
||||
exports.localBaseline = "tests/baselines/local/";
|
||||
exports.refBaseline = "tests/baselines/reference/";
|
||||
exports.localRwcBaseline = "internal/baselines/rwc/local";
|
||||
@@ -27,7 +27,6 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
|
||||
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
|
||||
let testTimeout = cmdLineOptions.timeout;
|
||||
let tests = cmdLineOptions.tests;
|
||||
const lintFlag = cmdLineOptions.lint;
|
||||
const debug = cmdLineOptions.debug;
|
||||
const inspect = cmdLineOptions.inspect;
|
||||
const runners = cmdLineOptions.runners;
|
||||
@@ -117,9 +116,6 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
|
||||
errorStatus = exitCode;
|
||||
error = new Error(`Process exited with status code ${errorStatus}.`);
|
||||
}
|
||||
else if (lintFlag) {
|
||||
await new Promise((resolve, reject) => gulp.start(["lint"], error => error ? reject(error) : resolve()));
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
errorStatus = undefined;
|
||||
@@ -144,10 +140,10 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
|
||||
}
|
||||
exports.runConsoleTests = runConsoleTests;
|
||||
|
||||
function cleanTestDirs() {
|
||||
return del([exports.localBaseline, exports.localRwcBaseline])
|
||||
.then(() => mkdirP(exports.localRwcBaseline))
|
||||
.then(() => mkdirP(exports.localBaseline));
|
||||
async function cleanTestDirs() {
|
||||
await del([exports.localBaseline, exports.localRwcBaseline])
|
||||
mkdirP.sync(exports.localRwcBaseline);
|
||||
mkdirP.sync(exports.localBaseline);
|
||||
}
|
||||
exports.cleanTestDirs = cleanTestDirs;
|
||||
|
||||
|
||||
@@ -1,435 +0,0 @@
|
||||
// @ts-check
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
|
||||
const ts = require("../../lib/typescript");
|
||||
const { Duplex } = require("stream");
|
||||
const chalk = /**@type {*} */(require("chalk"));
|
||||
const Vinyl = require("vinyl");
|
||||
|
||||
/**
|
||||
* Creates a stream that passes through its inputs only if the project outputs are not up to date
|
||||
* with respect to the inputs.
|
||||
* @param {ParsedCommandLine} parsedProject
|
||||
* @param {UpToDateOptions} [options]
|
||||
*
|
||||
* @typedef UpToDateOptions
|
||||
* @property {boolean | "minimal"} [verbose]
|
||||
* @property {(configFilePath: string) => ParsedCommandLine | undefined} [parseProject]
|
||||
*/
|
||||
function upToDate(parsedProject, options) {
|
||||
/** @type {File[]} */
|
||||
const inputs = [];
|
||||
/** @type {Map<string, File>} */
|
||||
const inputMap = new Map();
|
||||
/** @type {Map<string, fs.Stats>} */
|
||||
const statCache = new Map();
|
||||
/** @type {UpToDateHost} */
|
||||
const upToDateHost = {
|
||||
fileExists(fileName) {
|
||||
const stats = getStat(fileName);
|
||||
return stats ? stats.isFile() : false;
|
||||
},
|
||||
getModifiedTime(fileName) {
|
||||
return getStat(fileName).mtime;
|
||||
},
|
||||
parseConfigFile: options && options.parseProject
|
||||
};
|
||||
const duplex = new Duplex({
|
||||
objectMode: true,
|
||||
/**
|
||||
* @param {string|Buffer|File} file
|
||||
*/
|
||||
write(file, _, cb) {
|
||||
if (typeof file === "string" || Buffer.isBuffer(file)) return cb(new Error("Only Vinyl files are supported."));
|
||||
inputs.push(file);
|
||||
inputMap.set(path.resolve(file.path), file);
|
||||
cb();
|
||||
},
|
||||
final(cb) {
|
||||
const status = getUpToDateStatus(upToDateHost, parsedProject);
|
||||
reportStatus(parsedProject, status, options);
|
||||
if (status.type !== UpToDateStatusType.UpToDate) {
|
||||
for (const input of inputs) duplex.push(input);
|
||||
}
|
||||
duplex.push(null);
|
||||
inputMap.clear();
|
||||
statCache.clear();
|
||||
cb();
|
||||
},
|
||||
read() {
|
||||
}
|
||||
});
|
||||
return duplex;
|
||||
|
||||
function getStat(fileName) {
|
||||
fileName = path.resolve(fileName);
|
||||
const inputFile = inputMap.get(fileName);
|
||||
if (inputFile && inputFile.stat) return inputFile.stat;
|
||||
|
||||
let stats = statCache.get(fileName);
|
||||
if (!stats && fs.existsSync(fileName)) {
|
||||
stats = fs.statSync(fileName);
|
||||
statCache.set(fileName, stats);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
module.exports = exports = upToDate;
|
||||
|
||||
/**
|
||||
* @param {DiagnosticMessage} message
|
||||
* @param {...string} args
|
||||
*/
|
||||
function formatMessage(message, ...args) {
|
||||
log.info(formatStringFromArgs(message.message, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ParsedCommandLine} project
|
||||
* @param {UpToDateStatus} status
|
||||
* @param {{verbose?: boolean | "minimal"}} options
|
||||
*/
|
||||
function reportStatus(project, status, options) {
|
||||
switch (options.verbose) {
|
||||
case "minimal":
|
||||
switch (status.type) {
|
||||
case UpToDateStatusType.UpToDate:
|
||||
log.info(`Project '${fileName(project.options.configFilePath)}' is up to date.`);
|
||||
break;
|
||||
default:
|
||||
log.info(`Project '${fileName(project.options.configFilePath)}' is out of date, rebuilding...`);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case true:
|
||||
/**@type {*}*/(ts).formatUpToDateStatus(project.options.configFilePath, status, fileName, formatMessage);
|
||||
break;
|
||||
}
|
||||
if (!options.verbose) return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @private
|
||||
*/
|
||||
function normalizeSlashes(file) {
|
||||
return file.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @private
|
||||
*/
|
||||
function fileName(file) {
|
||||
return chalk.cyan(normalizeSlashes(path.relative(process.cwd(), path.resolve(file))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {string[]} args
|
||||
* @param {number} [baseIndex]
|
||||
*/
|
||||
function formatStringFromArgs(text, args, baseIndex = 0) {
|
||||
return text.replace(/{(\d+)}/g, (_match, index) => args[+index + baseIndex]);
|
||||
}
|
||||
|
||||
const minimumDate = new Date(-8640000000000000);
|
||||
const maximumDate = new Date(8640000000000000);
|
||||
const missingFileModifiedTime = new Date(0);
|
||||
|
||||
/**
|
||||
* @typedef {0} UpToDateStatusType.Unbuildable
|
||||
* @typedef {1} UpToDateStatusType.UpToDate
|
||||
* @typedef {2} UpToDateStatusType.UpToDateWithUpstreamTypes
|
||||
* @typedef {3} UpToDateStatusType.OutputMissing
|
||||
* @typedef {4} UpToDateStatusType.OutOfDateWithSelf
|
||||
* @typedef {5} UpToDateStatusType.OutOfDateWithUpstream
|
||||
* @typedef {6} UpToDateStatusType.UpstreamOutOfDate
|
||||
* @typedef {7} UpToDateStatusType.UpstreamBlocked
|
||||
* @typedef {8} UpToDateStatusType.ComputingUpstream
|
||||
* @typedef {9} UpToDateStatusType.ContainerOnly
|
||||
* @enum {UpToDateStatusType.Unbuildable | UpToDateStatusType.UpToDate | UpToDateStatusType.UpToDateWithUpstreamTypes | UpToDateStatusType.OutputMissing | UpToDateStatusType.OutOfDateWithSelf | UpToDateStatusType.OutOfDateWithUpstream | UpToDateStatusType.UpstreamOutOfDate | UpToDateStatusType.UpstreamBlocked | UpToDateStatusType.ComputingUpstream | UpToDateStatusType.ContainerOnly}
|
||||
*/
|
||||
const UpToDateStatusType = {
|
||||
Unbuildable: /** @type {0} */(0),
|
||||
UpToDate: /** @type {1} */(1),
|
||||
UpToDateWithUpstreamTypes: /** @type {2} */(2),
|
||||
OutputMissing: /** @type {3} */(3),
|
||||
OutOfDateWithSelf: /** @type {4} */(4),
|
||||
OutOfDateWithUpstream: /** @type {5} */(5),
|
||||
UpstreamOutOfDate: /** @type {6} */(6),
|
||||
UpstreamBlocked: /** @type {7} */(7),
|
||||
ComputingUpstream: /** @type {8} */(8),
|
||||
ContainerOnly: /** @type {9} */(9),
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Date} date1
|
||||
* @param {Date} date2
|
||||
* @returns {Date}
|
||||
*/
|
||||
function newer(date1, date2) {
|
||||
return date2 > date1 ? date2 : date1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {UpToDateHost} host
|
||||
* @param {ParsedCommandLine | undefined} project
|
||||
* @returns {UpToDateStatus}
|
||||
*/
|
||||
function getUpToDateStatus(host, project) {
|
||||
if (project === undefined) return { type: UpToDateStatusType.Unbuildable, reason: "File deleted mid-build" };
|
||||
const prior = host.getLastStatus ? host.getLastStatus(project.options.configFilePath) : undefined;
|
||||
if (prior !== undefined) {
|
||||
return prior;
|
||||
}
|
||||
const actual = getUpToDateStatusWorker(host, project);
|
||||
if (host.setLastStatus) {
|
||||
host.setLastStatus(project.options.configFilePath, actual);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {UpToDateHost} host
|
||||
* @param {ParsedCommandLine | undefined} project
|
||||
* @returns {UpToDateStatus}
|
||||
*/
|
||||
function getUpToDateStatusWorker(host, project) {
|
||||
/** @type {string} */
|
||||
let newestInputFileName = undefined;
|
||||
let newestInputFileTime = minimumDate;
|
||||
// Get timestamps of input files
|
||||
for (const inputFile of project.fileNames) {
|
||||
if (!host.fileExists(inputFile)) {
|
||||
return {
|
||||
type: UpToDateStatusType.Unbuildable,
|
||||
reason: `${inputFile} does not exist`
|
||||
};
|
||||
}
|
||||
|
||||
const inputTime = host.getModifiedTime(inputFile) || missingFileModifiedTime;
|
||||
if (inputTime > newestInputFileTime) {
|
||||
newestInputFileName = inputFile;
|
||||
newestInputFileTime = inputTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Collect the expected outputs of this project
|
||||
const outputs = /**@type {string[]}*/(/**@type {*}*/(ts).getAllProjectOutputs(project));
|
||||
|
||||
if (outputs.length === 0) {
|
||||
return {
|
||||
type: UpToDateStatusType.ContainerOnly
|
||||
};
|
||||
}
|
||||
|
||||
// Now see if all outputs are newer than the newest input
|
||||
let oldestOutputFileName = "(none)";
|
||||
let oldestOutputFileTime = maximumDate;
|
||||
let newestOutputFileName = "(none)";
|
||||
let newestOutputFileTime = minimumDate;
|
||||
/** @type {string | undefined} */
|
||||
let missingOutputFileName;
|
||||
let newestDeclarationFileContentChangedTime = minimumDate;
|
||||
let isOutOfDateWithInputs = false;
|
||||
for (const output of outputs) {
|
||||
// Output is missing; can stop checking
|
||||
// Don't immediately return because we can still be upstream-blocked, which is a higher-priority status
|
||||
if (!host.fileExists(output)) {
|
||||
missingOutputFileName = output;
|
||||
break;
|
||||
}
|
||||
|
||||
const outputTime = host.getModifiedTime(output) || missingFileModifiedTime;
|
||||
if (outputTime < oldestOutputFileTime) {
|
||||
oldestOutputFileTime = outputTime;
|
||||
oldestOutputFileName = output;
|
||||
}
|
||||
|
||||
// If an output is older than the newest input, we can stop checking
|
||||
// Don't immediately return because we can still be upstream-blocked, which is a higher-priority status
|
||||
if (outputTime < newestInputFileTime) {
|
||||
isOutOfDateWithInputs = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (outputTime > newestOutputFileTime) {
|
||||
newestOutputFileTime = outputTime;
|
||||
newestOutputFileName = output;
|
||||
}
|
||||
|
||||
// Keep track of when the most recent time a .d.ts file was changed.
|
||||
// In addition to file timestamps, we also keep track of when a .d.ts file
|
||||
// had its file touched but not had its contents changed - this allows us
|
||||
// to skip a downstream typecheck
|
||||
if (path.extname(output) === ".d.ts") {
|
||||
const unchangedTime = host.getUnchangedTime ? host.getUnchangedTime(output) : undefined;
|
||||
if (unchangedTime !== undefined) {
|
||||
newestDeclarationFileContentChangedTime = newer(unchangedTime, newestDeclarationFileContentChangedTime);
|
||||
}
|
||||
else {
|
||||
const outputModifiedTime = host.getModifiedTime(output) || missingFileModifiedTime;
|
||||
newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, outputModifiedTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pseudoUpToDate = false;
|
||||
let usesPrepend = false;
|
||||
/** @type {string | undefined} */
|
||||
let upstreamChangedProject;
|
||||
if (project.projectReferences) {
|
||||
if (host.setLastStatus) host.setLastStatus(project.options.configFilePath, { type: UpToDateStatusType.ComputingUpstream });
|
||||
for (const ref of project.projectReferences) {
|
||||
usesPrepend = usesPrepend || !!(ref.prepend);
|
||||
const resolvedRef = ts.resolveProjectReferencePath(host, ref);
|
||||
const parsedRef = host.parseConfigFile ? host.parseConfigFile(resolvedRef) : ts.getParsedCommandLineOfConfigFile(resolvedRef, {}, parseConfigHost);
|
||||
const refStatus = getUpToDateStatus(host, parsedRef);
|
||||
|
||||
// Its a circular reference ignore the status of this project
|
||||
if (refStatus.type === UpToDateStatusType.ComputingUpstream) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// An upstream project is blocked
|
||||
if (refStatus.type === UpToDateStatusType.Unbuildable) {
|
||||
return {
|
||||
type: UpToDateStatusType.UpstreamBlocked,
|
||||
upstreamProjectName: ref.path
|
||||
};
|
||||
}
|
||||
|
||||
// If the upstream project is out of date, then so are we (someone shouldn't have asked, though?)
|
||||
if (refStatus.type !== UpToDateStatusType.UpToDate) {
|
||||
return {
|
||||
type: UpToDateStatusType.UpstreamOutOfDate,
|
||||
upstreamProjectName: ref.path
|
||||
};
|
||||
}
|
||||
|
||||
// If the upstream project's newest file is older than our oldest output, we
|
||||
// can't be out of date because of it
|
||||
if (refStatus.newestInputFileTime && refStatus.newestInputFileTime <= oldestOutputFileTime) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the upstream project has only change .d.ts files, and we've built
|
||||
// *after* those files, then we're "psuedo up to date" and eligible for a fast rebuild
|
||||
if (refStatus.newestDeclarationFileContentChangedTime && refStatus.newestDeclarationFileContentChangedTime <= oldestOutputFileTime) {
|
||||
pseudoUpToDate = true;
|
||||
upstreamChangedProject = ref.path;
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have an output older than an upstream output - we are out of date
|
||||
return {
|
||||
type: UpToDateStatusType.OutOfDateWithUpstream,
|
||||
outOfDateOutputFileName: oldestOutputFileName,
|
||||
newerProjectName: ref.path
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (missingOutputFileName !== undefined) {
|
||||
return {
|
||||
type: UpToDateStatusType.OutputMissing,
|
||||
missingOutputFileName
|
||||
};
|
||||
}
|
||||
|
||||
if (isOutOfDateWithInputs) {
|
||||
return {
|
||||
type: UpToDateStatusType.OutOfDateWithSelf,
|
||||
outOfDateOutputFileName: oldestOutputFileName,
|
||||
newerInputFileName: newestInputFileName
|
||||
};
|
||||
}
|
||||
|
||||
if (usesPrepend && pseudoUpToDate) {
|
||||
return {
|
||||
type: UpToDateStatusType.OutOfDateWithUpstream,
|
||||
outOfDateOutputFileName: oldestOutputFileName,
|
||||
newerProjectName: upstreamChangedProject
|
||||
};
|
||||
}
|
||||
|
||||
// Up to date
|
||||
return {
|
||||
type: pseudoUpToDate ? UpToDateStatusType.UpToDateWithUpstreamTypes : UpToDateStatusType.UpToDate,
|
||||
newestDeclarationFileContentChangedTime,
|
||||
newestInputFileTime,
|
||||
newestOutputFileTime,
|
||||
newestInputFileName,
|
||||
newestOutputFileName,
|
||||
oldestOutputFileName
|
||||
};
|
||||
}
|
||||
|
||||
const parseConfigHost = {
|
||||
useCaseSensitiveFileNames: true,
|
||||
getCurrentDirectory: () => process.cwd(),
|
||||
readDirectory: (file) => fs.readdirSync(file),
|
||||
fileExists: file => fs.existsSync(file) && fs.statSync(file).isFile(),
|
||||
readFile: file => fs.readFileSync(file, "utf8"),
|
||||
onUnRecoverableConfigFileDiagnostic: () => undefined
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {import("vinyl")} File
|
||||
* @typedef {import("../../lib/typescript").ParsedCommandLine & { options: CompilerOptions }} ParsedCommandLine
|
||||
* @typedef {import("../../lib/typescript").CompilerOptions & { configFilePath?: string }} CompilerOptions
|
||||
* @typedef {import("../../lib/typescript").DiagnosticMessage} DiagnosticMessage
|
||||
* @typedef UpToDateHost
|
||||
* @property {(fileName: string) => boolean} fileExists
|
||||
* @property {(fileName: string) => Date} getModifiedTime
|
||||
* @property {(fileName: string) => Date} [getUnchangedTime]
|
||||
* @property {(configFilePath: string) => ParsedCommandLine | undefined} parseConfigFile
|
||||
* @property {(configFilePath: string) => UpToDateStatus} [getLastStatus]
|
||||
* @property {(configFilePath: string, status: UpToDateStatus) => void} [setLastStatus]
|
||||
*
|
||||
* @typedef Status.Unbuildable
|
||||
* @property {UpToDateStatusType.Unbuildable} type
|
||||
* @property {string} reason
|
||||
*
|
||||
* @typedef Status.ContainerOnly
|
||||
* @property {UpToDateStatusType.ContainerOnly} type
|
||||
*
|
||||
* @typedef Status.UpToDate
|
||||
* @property {UpToDateStatusType.UpToDate | UpToDateStatusType.UpToDateWithUpstreamTypes} type
|
||||
* @property {Date} [newestInputFileTime]
|
||||
* @property {string} [newestInputFileName]
|
||||
* @property {Date} [newestDeclarationFileContentChangedTime]
|
||||
* @property {Date} [newestOutputFileTime]
|
||||
* @property {string} [newestOutputFileName]
|
||||
* @property {string} [oldestOutputFileName]
|
||||
*
|
||||
* @typedef Status.OutputMissing
|
||||
* @property {UpToDateStatusType.OutputMissing} type
|
||||
* @property {string} missingOutputFileName
|
||||
*
|
||||
* @typedef Status.OutOfDateWithSelf
|
||||
* @property {UpToDateStatusType.OutOfDateWithSelf} type
|
||||
* @property {string} outOfDateOutputFileName
|
||||
* @property {string} newerInputFileName
|
||||
*
|
||||
* @typedef Status.UpstreamOutOfDate
|
||||
* @property {UpToDateStatusType.UpstreamOutOfDate} type
|
||||
* @property {string} upstreamProjectName
|
||||
*
|
||||
* @typedef Status.UpstreamBlocked
|
||||
* @property {UpToDateStatusType.UpstreamBlocked} type
|
||||
* @property {string} upstreamProjectName
|
||||
*
|
||||
* @typedef Status.ComputingUpstream
|
||||
* @property {UpToDateStatusType.ComputingUpstream} type
|
||||
*
|
||||
* @typedef Status.OutOfDateWithUpstream
|
||||
* @property {UpToDateStatusType.OutOfDateWithUpstream} type
|
||||
* @property {string} outOfDateOutputFileName
|
||||
* @property {string} newerProjectName
|
||||
|
||||
* @typedef {Status.Unbuildable | Status.ContainerOnly | Status.UpToDate | Status.OutputMissing | Status.OutOfDateWithSelf | Status.UpstreamOutOfDate | Status.UpstreamBlocked | Status.ComputingUpstream | Status.OutOfDateWithUpstream} UpToDateStatus
|
||||
*/
|
||||
void 0;
|
||||
+410
-3
@@ -1,7 +1,119 @@
|
||||
// @ts-check
|
||||
/// <reference path="../types/ambient.d.ts" />
|
||||
|
||||
const fs = require("fs");
|
||||
const File = require("./vinyl");
|
||||
const { Readable } = require("stream");
|
||||
const path = require("path");
|
||||
const log = require("fancy-log");
|
||||
const mkdirp = require("mkdirp");
|
||||
const del = require("del");
|
||||
const File = require("vinyl");
|
||||
const ts = require("../../lib/typescript");
|
||||
const { default: chalk } = require("chalk");
|
||||
const { spawn } = require("child_process");
|
||||
const { CancellationToken, CancelError, Deferred } = require("prex");
|
||||
const { Readable, Duplex } = require("stream");
|
||||
|
||||
const isWindows = /^win/.test(process.platform);
|
||||
|
||||
/**
|
||||
* Executes the provided command once with the supplied arguments.
|
||||
* @param {string} cmd
|
||||
* @param {string[]} args
|
||||
* @param {ExecOptions} [options]
|
||||
*
|
||||
* @typedef ExecOptions
|
||||
* @property {boolean} [ignoreExitCode]
|
||||
* @property {import("prex").CancellationToken} [cancelToken]
|
||||
* @property {boolean} [hidePrompt]
|
||||
*/
|
||||
function exec(cmd, args, options = {}) {
|
||||
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
|
||||
const { ignoreExitCode, cancelToken = CancellationToken.none } = options;
|
||||
cancelToken.throwIfCancellationRequested();
|
||||
|
||||
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
|
||||
const subshellFlag = isWindows ? "/c" : "-c";
|
||||
const command = isWindows ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`];
|
||||
|
||||
if (!options.hidePrompt) log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
|
||||
const proc = spawn(isWindows ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
|
||||
const registration = cancelToken.register(() => {
|
||||
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
|
||||
proc.kill("SIGINT");
|
||||
proc.kill("SIGTERM");
|
||||
reject(new CancelError());
|
||||
});
|
||||
proc.on("exit", exitCode => {
|
||||
registration.unregister();
|
||||
if (exitCode === 0 || ignoreExitCode) {
|
||||
resolve({ exitCode });
|
||||
}
|
||||
else {
|
||||
reject(new Error(`Process exited with code: ${exitCode}`));
|
||||
}
|
||||
});
|
||||
proc.on("error", error => {
|
||||
registration.unregister();
|
||||
reject(error);
|
||||
});
|
||||
}));
|
||||
}
|
||||
exports.exec = exec;
|
||||
|
||||
/**
|
||||
* @param {string} cmd
|
||||
*/
|
||||
function possiblyQuote(cmd) {
|
||||
return cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ts.Diagnostic[]} diagnostics
|
||||
* @param {{ cwd?: string, pretty?: boolean }} [options]
|
||||
*/
|
||||
function formatDiagnostics(diagnostics, options) {
|
||||
return options && options.pretty
|
||||
? ts.formatDiagnosticsWithColorAndContext(diagnostics, getFormatDiagnosticsHost(options && options.cwd))
|
||||
: ts.formatDiagnostics(diagnostics, getFormatDiagnosticsHost(options && options.cwd));
|
||||
}
|
||||
exports.formatDiagnostics = formatDiagnostics;
|
||||
|
||||
/**
|
||||
* @param {ts.Diagnostic[]} diagnostics
|
||||
* @param {{ cwd?: string }} [options]
|
||||
*/
|
||||
function reportDiagnostics(diagnostics, options) {
|
||||
log(formatDiagnostics(diagnostics, { cwd: options && options.cwd, pretty: process.stdout.isTTY }));
|
||||
}
|
||||
exports.reportDiagnostics = reportDiagnostics;
|
||||
|
||||
/**
|
||||
* @param {string | undefined} cwd
|
||||
* @returns {ts.FormatDiagnosticsHost}
|
||||
*/
|
||||
function getFormatDiagnosticsHost(cwd) {
|
||||
return {
|
||||
getCanonicalFileName: fileName => fileName,
|
||||
getCurrentDirectory: () => cwd,
|
||||
getNewLine: () => ts.sys.newLine,
|
||||
};
|
||||
}
|
||||
exports.getFormatDiagnosticsHost = getFormatDiagnosticsHost;
|
||||
|
||||
/**
|
||||
* Reads JSON data with optional comments using the LKG TypeScript compiler
|
||||
* @param {string} jsonPath
|
||||
*/
|
||||
function readJson(jsonPath) {
|
||||
const jsonText = fs.readFileSync(jsonPath, "utf8");
|
||||
const result = ts.parseConfigFileTextToJson(jsonPath, jsonText);
|
||||
if (result.error) {
|
||||
reportDiagnostics([result.error]);
|
||||
throw new Error("An error occurred during parse.");
|
||||
}
|
||||
return result.config;
|
||||
}
|
||||
exports.readJson = readJson;
|
||||
|
||||
/**
|
||||
* @param {File} file
|
||||
@@ -24,4 +136,299 @@ function streamFromBuffer(buffer) {
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.streamFromBuffer = streamFromBuffer;
|
||||
exports.streamFromBuffer = streamFromBuffer;
|
||||
|
||||
/**
|
||||
* @param {string | string[]} source
|
||||
* @param {string | string[]} dest
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function needsUpdate(source, dest) {
|
||||
if (typeof source === "string" && typeof dest === "string") {
|
||||
if (fs.existsSync(dest)) {
|
||||
const {mtime: outTime} = fs.statSync(dest);
|
||||
const {mtime: inTime} = fs.statSync(source);
|
||||
if (+inTime <= +outTime) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof source === "string" && typeof dest !== "string") {
|
||||
const {mtime: inTime} = fs.statSync(source);
|
||||
for (const filepath of dest) {
|
||||
if (fs.existsSync(filepath)) {
|
||||
const {mtime: outTime} = fs.statSync(filepath);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (typeof source !== "string" && typeof dest === "string") {
|
||||
if (fs.existsSync(dest)) {
|
||||
const {mtime: outTime} = fs.statSync(dest);
|
||||
for (const filepath of source) {
|
||||
if (fs.existsSync(filepath)) {
|
||||
const {mtime: inTime} = fs.statSync(filepath);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (typeof source !== "string" && typeof dest !== "string") {
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
if (!dest[i]) {
|
||||
continue;
|
||||
}
|
||||
if (fs.existsSync(dest[i])) {
|
||||
const {mtime: outTime} = fs.statSync(dest[i]);
|
||||
const {mtime: inTime} = fs.statSync(source[i]);
|
||||
if (+inTime > +outTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.needsUpdate = needsUpdate;
|
||||
|
||||
function getDiffTool() {
|
||||
const program = process.env.DIFF;
|
||||
if (!program) {
|
||||
log.warn("Add the 'DIFF' environment variable to the path of the program you want to use.");
|
||||
process.exit(1);
|
||||
}
|
||||
return program;
|
||||
}
|
||||
exports.getDiffTool = getDiffTool;
|
||||
|
||||
/**
|
||||
* Find the size of a directory recursively.
|
||||
* Symbolic links can cause a loop.
|
||||
* @param {string} root
|
||||
* @returns {number} bytes
|
||||
*/
|
||||
function getDirSize(root) {
|
||||
const stats = fs.lstatSync(root);
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
return stats.size;
|
||||
}
|
||||
|
||||
return fs.readdirSync(root)
|
||||
.map(file => getDirSize(path.join(root, file)))
|
||||
.reduce((acc, num) => acc + num, 0);
|
||||
}
|
||||
exports.getDirSize = getDirSize;
|
||||
|
||||
/**
|
||||
* Flattens a project with project references into a single project.
|
||||
* @param {string} projectSpec The path to a tsconfig.json file or its containing directory.
|
||||
* @param {string} flattenedProjectSpec The output path for the flattened tsconfig.json file.
|
||||
* @param {FlattenOptions} [options] Options used to flatten a project hierarchy.
|
||||
*
|
||||
* @typedef FlattenOptions
|
||||
* @property {string} [cwd] The path to use for the current working directory. Defaults to `process.cwd()`.
|
||||
* @property {import("../../lib/typescript").CompilerOptions} [compilerOptions] Compiler option overrides.
|
||||
* @property {boolean} [force] Forces creation of the output project.
|
||||
* @property {string[]} [exclude] Files to exclude (relative to `cwd`)
|
||||
*/
|
||||
function flatten(projectSpec, flattenedProjectSpec, options = {}) {
|
||||
const cwd = normalizeSlashes(options.cwd ? path.resolve(options.cwd) : process.cwd());
|
||||
const files = [];
|
||||
const resolvedOutputSpec = path.resolve(cwd, flattenedProjectSpec);
|
||||
const resolvedOutputDirectory = path.dirname(resolvedOutputSpec);
|
||||
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, undefined);
|
||||
const project = readJson(resolvedProjectSpec);
|
||||
const skipProjects = /**@type {Set<string>}*/(new Set());
|
||||
const skipFiles = new Set(options && options.exclude && options.exclude.map(file => normalizeSlashes(path.resolve(cwd, file))));
|
||||
recur(resolvedProjectSpec, project);
|
||||
|
||||
if (options.force || needsUpdate(files, resolvedOutputSpec)) {
|
||||
const config = {
|
||||
extends: normalizeSlashes(path.relative(resolvedOutputDirectory, resolvedProjectSpec)),
|
||||
compilerOptions: options.compilerOptions || {},
|
||||
files: files.map(file => normalizeSlashes(path.relative(resolvedOutputDirectory, file)))
|
||||
};
|
||||
mkdirp.sync(resolvedOutputDirectory);
|
||||
fs.writeFileSync(resolvedOutputSpec, JSON.stringify(config, undefined, 2), "utf8");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} projectSpec
|
||||
* @param {object} project
|
||||
*/
|
||||
function recur(projectSpec, project) {
|
||||
if (skipProjects.has(projectSpec)) return;
|
||||
skipProjects.add(project);
|
||||
if (project.references) {
|
||||
for (const ref of project.references) {
|
||||
const referencedSpec = resolveProjectSpec(ref.path, cwd, projectSpec);
|
||||
const referencedProject = readJson(referencedSpec);
|
||||
recur(referencedSpec, referencedProject);
|
||||
}
|
||||
}
|
||||
if (project.include) {
|
||||
throw new Error("Flattened project may not have an 'include' list.");
|
||||
}
|
||||
if (!project.files) {
|
||||
throw new Error("Flattened project must have an explicit 'files' list.");
|
||||
}
|
||||
const projectDirectory = path.dirname(projectSpec);
|
||||
for (let file of project.files) {
|
||||
file = normalizeSlashes(path.resolve(projectDirectory, file));
|
||||
if (skipFiles.has(file)) continue;
|
||||
skipFiles.add(file);
|
||||
files.push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.flatten = flatten;
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
*/
|
||||
function normalizeSlashes(file) {
|
||||
return file.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} projectSpec
|
||||
* @param {string} cwd
|
||||
* @param {string | undefined} referrer
|
||||
* @returns {string}
|
||||
*/
|
||||
function resolveProjectSpec(projectSpec, cwd, referrer) {
|
||||
let projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
|
||||
const stats = fs.statSync(projectPath);
|
||||
if (stats.isFile()) return normalizeSlashes(projectPath);
|
||||
return normalizeSlashes(path.resolve(cwd, projectPath, "tsconfig.json"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | ((file: File) => string) | { cwd?: string }} [dest]
|
||||
* @param {{ cwd?: string }} [opts]
|
||||
*/
|
||||
function rm(dest, opts) {
|
||||
if (dest && typeof dest === "object") opts = dest, dest = undefined;
|
||||
let failed = false;
|
||||
|
||||
const cwd = path.resolve(opts && opts.cwd || process.cwd());
|
||||
|
||||
/** @type {{ file: File, deleted: boolean, promise: Promise<any>, cb: Function }[]} */
|
||||
const pending = [];
|
||||
|
||||
const processDeleted = () => {
|
||||
if (failed) return;
|
||||
while (pending.length && pending[0].deleted) {
|
||||
const { file, cb } = pending.shift();
|
||||
duplex.push(file);
|
||||
cb();
|
||||
}
|
||||
};
|
||||
|
||||
const duplex = new Duplex({
|
||||
objectMode: true,
|
||||
/**
|
||||
* @param {string|Buffer|File} file
|
||||
*/
|
||||
write(file, _, cb) {
|
||||
if (failed) return;
|
||||
if (typeof file === "string" || Buffer.isBuffer(file)) return cb(new Error("Only Vinyl files are supported."));
|
||||
const basePath = typeof dest === "string" ? path.resolve(cwd, dest) :
|
||||
typeof dest === "function" ? path.resolve(cwd, dest(file)) :
|
||||
file.base;
|
||||
const filePath = path.resolve(basePath, file.relative);
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
file.path = filePath;
|
||||
const entry = {
|
||||
file,
|
||||
deleted: false,
|
||||
cb,
|
||||
promise: del(file.path).then(() => {
|
||||
entry.deleted = true;
|
||||
processDeleted();
|
||||
}, err => {
|
||||
failed = true;
|
||||
pending.length = 0;
|
||||
cb(err);
|
||||
})
|
||||
};
|
||||
pending.push(entry);
|
||||
},
|
||||
final(cb) {
|
||||
processDeleted();
|
||||
if (pending.length) {
|
||||
Promise
|
||||
.all(pending.map(entry => entry.promise))
|
||||
.then(() => processDeleted())
|
||||
.then(() => cb(), cb);
|
||||
return;
|
||||
}
|
||||
cb();
|
||||
},
|
||||
read() {
|
||||
}
|
||||
});
|
||||
return duplex;
|
||||
}
|
||||
exports.rm = rm;
|
||||
|
||||
class Debouncer {
|
||||
/**
|
||||
* @param {number} timeout
|
||||
* @param {() => Promise<any>} action
|
||||
*/
|
||||
constructor(timeout, action) {
|
||||
this._timeout = timeout;
|
||||
this._action = action;
|
||||
}
|
||||
|
||||
enqueue() {
|
||||
if (this._timer) {
|
||||
clearTimeout(this._timer);
|
||||
this._timer = undefined;
|
||||
}
|
||||
|
||||
if (!this._deferred) {
|
||||
this._deferred = new Deferred();
|
||||
}
|
||||
|
||||
this._timer = setTimeout(() => this.run(), 100);
|
||||
return this._deferred.promise;
|
||||
}
|
||||
|
||||
run() {
|
||||
if (this._timer) {
|
||||
clearTimeout(this._timer);
|
||||
this._timer = undefined;
|
||||
}
|
||||
|
||||
const deferred = this._deferred;
|
||||
this._deferred = undefined;
|
||||
this._projects = undefined;
|
||||
try {
|
||||
deferred.resolve(this._action());
|
||||
}
|
||||
catch (e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Debouncer = Debouncer;
|
||||
Vendored
-60
@@ -1,60 +0,0 @@
|
||||
// NOTE: This makes it possible to correctly type vinyl Files under @ts-check.
|
||||
export = File;
|
||||
|
||||
declare class File<T extends File.Contents = File.Contents> {
|
||||
constructor(options?: File.VinylOptions<T>);
|
||||
|
||||
cwd: string;
|
||||
base: string;
|
||||
path: string;
|
||||
readonly history: ReadonlyArray<string>;
|
||||
contents: T;
|
||||
relative: string;
|
||||
dirname: string;
|
||||
basename: string;
|
||||
stem: string;
|
||||
extname: string;
|
||||
symlink: string | null;
|
||||
stat: import("fs").Stats | null;
|
||||
sourceMap?: import("./sourcemaps").RawSourceMap | string;
|
||||
|
||||
[custom: string]: any;
|
||||
|
||||
isBuffer(): this is T extends Buffer ? File<Buffer> : never;
|
||||
isStream(): this is T extends NodeJS.ReadableStream ? File<NodeJS.ReadableStream> : never;
|
||||
isNull(): this is T extends null ? File<null> : never;
|
||||
isDirectory(): this is T extends null ? File.Directory : never;
|
||||
isSymbolic(): this is T extends null ? File.Symbolic : never;
|
||||
clone(opts?: { contents?: boolean, deep?: boolean }): this;
|
||||
}
|
||||
|
||||
namespace File {
|
||||
export interface VinylOptions<T extends Contents = Contents> {
|
||||
cwd?: string;
|
||||
base?: string;
|
||||
path?: string;
|
||||
history?: ReadonlyArray<string>;
|
||||
stat?: import("fs").Stats;
|
||||
contents?: T;
|
||||
sourceMap?: import("./sourcemaps").RawSourceMap | string;
|
||||
[custom: string]: any;
|
||||
}
|
||||
|
||||
export type Contents = Buffer | NodeJS.ReadableStream | null;
|
||||
export type File = import("./vinyl");
|
||||
export type NullFile = File<null>;
|
||||
export type BufferFile = File<Buffer>;
|
||||
export type StreamFile = File<NodeJS.ReadableStream>;
|
||||
|
||||
export interface Directory extends NullFile {
|
||||
isNull(): true;
|
||||
isDirectory(): true;
|
||||
isSymbolic(): this is never;
|
||||
}
|
||||
|
||||
export interface Symbolic extends NullFile {
|
||||
isNull(): true;
|
||||
isDirectory(): this is never;
|
||||
isSymbolic(): true;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require("vinyl");
|
||||
@@ -1,3 +1,5 @@
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
|
||||
import cp = require("child_process");
|
||||
import Octokit = require("@octokit/rest");
|
||||
|
||||
@@ -35,7 +37,7 @@ gh.authenticate({
|
||||
type: "token",
|
||||
token: process.argv[2]
|
||||
});
|
||||
gh.pullRequests.create({
|
||||
gh.pulls.create({
|
||||
owner: process.env.TARGET_FORK,
|
||||
repo: "TypeScript",
|
||||
maintainer_can_modify: true,
|
||||
@@ -50,7 +52,7 @@ cc ${reviewers.map(r => "@" + r).join(" ")}`,
|
||||
}).then(r => {
|
||||
const num = r.data.number;
|
||||
console.log(`Pull request ${num} created.`);
|
||||
return gh.pullRequests.createReviewRequest({
|
||||
return gh.pulls.createReviewRequest({
|
||||
owner: process.env.TARGET_FORK,
|
||||
repo: "TypeScript",
|
||||
number: num,
|
||||
|
||||
Vendored
+77
@@ -1,3 +1,5 @@
|
||||
import { TaskFunction } from "gulp";
|
||||
|
||||
declare module "gulp-clone" {
|
||||
function Clone(): NodeJS.ReadWriteStream;
|
||||
namespace Clone {
|
||||
@@ -14,3 +16,78 @@ declare module "gulp-insert" {
|
||||
}
|
||||
|
||||
declare module "sorcery";
|
||||
|
||||
declare module "vinyl" {
|
||||
// NOTE: This makes it possible to correctly type vinyl Files under @ts-check.
|
||||
export = File;
|
||||
|
||||
declare class File<T extends File.Contents = File.Contents> {
|
||||
constructor(options?: File.VinylOptions<T>);
|
||||
|
||||
cwd: string;
|
||||
base: string;
|
||||
path: string;
|
||||
readonly history: ReadonlyArray<string>;
|
||||
contents: T;
|
||||
relative: string;
|
||||
dirname: string;
|
||||
basename: string;
|
||||
stem: string;
|
||||
extname: string;
|
||||
symlink: string | null;
|
||||
stat: import("fs").Stats | null;
|
||||
sourceMap?: import("./sourcemaps").RawSourceMap | string;
|
||||
|
||||
[custom: string]: any;
|
||||
|
||||
isBuffer(): this is T extends Buffer ? File<Buffer> : never;
|
||||
isStream(): this is T extends NodeJS.ReadableStream ? File<NodeJS.ReadableStream> : never;
|
||||
isNull(): this is T extends null ? File<null> : never;
|
||||
isDirectory(): this is T extends null ? File.Directory : never;
|
||||
isSymbolic(): this is T extends null ? File.Symbolic : never;
|
||||
clone(opts?: { contents?: boolean, deep?: boolean }): this;
|
||||
}
|
||||
|
||||
namespace File {
|
||||
export interface VinylOptions<T extends Contents = Contents> {
|
||||
cwd?: string;
|
||||
base?: string;
|
||||
path?: string;
|
||||
history?: ReadonlyArray<string>;
|
||||
stat?: import("fs").Stats;
|
||||
contents?: T;
|
||||
sourceMap?: import("./sourcemaps").RawSourceMap | string;
|
||||
[custom: string]: any;
|
||||
}
|
||||
|
||||
export type Contents = Buffer | NodeJS.ReadableStream | null;
|
||||
export type File = import("./vinyl");
|
||||
export type NullFile = File<null>;
|
||||
export type BufferFile = File<Buffer>;
|
||||
export type StreamFile = File<NodeJS.ReadableStream>;
|
||||
|
||||
export interface Directory extends NullFile {
|
||||
isNull(): true;
|
||||
isDirectory(): true;
|
||||
isSymbolic(): this is never;
|
||||
}
|
||||
|
||||
export interface Symbolic extends NullFile {
|
||||
isNull(): true;
|
||||
isDirectory(): this is never;
|
||||
isSymbolic(): true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module "undertaker" {
|
||||
interface TaskFunctionParams {
|
||||
flags?: Record<string, string>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "gulp-sourcemaps" {
|
||||
interface WriteOptions {
|
||||
destPath?: string;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../built/local/",
|
||||
"rootDir": ".",
|
||||
|
||||
+200
-143
@@ -67,6 +67,7 @@ namespace ts {
|
||||
let enumCount = 0;
|
||||
let instantiationDepth = 0;
|
||||
let constraintDepth = 0;
|
||||
let currentNode: Node | undefined;
|
||||
|
||||
const emptySymbols = createSymbolTable();
|
||||
const identityMapper: (type: Type) => Type = identity;
|
||||
@@ -3592,14 +3593,15 @@ namespace ts {
|
||||
|
||||
function typeReferenceToTypeNode(type: TypeReference) {
|
||||
const typeArguments: ReadonlyArray<Type> = type.typeArguments || emptyArray;
|
||||
if (type.target === globalArrayType) {
|
||||
if (type.target === globalArrayType || type.target === globalReadonlyArrayType) {
|
||||
if (context.flags & NodeBuilderFlags.WriteArrayAsGenericType) {
|
||||
const typeArgumentNode = typeToTypeNodeHelper(typeArguments[0], context);
|
||||
return createTypeReferenceNode("Array", [typeArgumentNode]);
|
||||
return createTypeReferenceNode(type.target === globalArrayType ? "Array" : "ReadonlyArray", [typeArgumentNode]);
|
||||
}
|
||||
|
||||
const elementType = typeToTypeNodeHelper(typeArguments[0], context);
|
||||
return createArrayTypeNode(elementType);
|
||||
const arrayType = createArrayTypeNode(elementType);
|
||||
return type.target === globalArrayType ? arrayType : createTypeOperatorNode(SyntaxKind.ReadonlyKeyword, arrayType);
|
||||
}
|
||||
else if (type.target.objectFlags & ObjectFlags.Tuple) {
|
||||
if (typeArguments.length > 0) {
|
||||
@@ -3612,11 +3614,13 @@ namespace ts {
|
||||
createRestTypeNode(createArrayTypeNode(tupleConstituentNodes[i])) :
|
||||
createOptionalTypeNode(tupleConstituentNodes[i]);
|
||||
}
|
||||
return createTupleTypeNode(tupleConstituentNodes);
|
||||
const tupleTypeNode = createTupleTypeNode(tupleConstituentNodes);
|
||||
return (<TupleType>type.target).readonly ? createTypeOperatorNode(SyntaxKind.ReadonlyKeyword, tupleTypeNode) : tupleTypeNode;
|
||||
}
|
||||
}
|
||||
if (context.encounteredError || (context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
|
||||
return createTupleTypeNode([]);
|
||||
const tupleTypeNode = createTupleTypeNode([]);
|
||||
return (<TupleType>type.target).readonly ? createTypeOperatorNode(SyntaxKind.ReadonlyKeyword, tupleTypeNode) : tupleTypeNode;
|
||||
}
|
||||
context.encounteredError = true;
|
||||
return undefined!; // TODO: GH#18217
|
||||
@@ -5280,17 +5284,18 @@ namespace ts {
|
||||
let objectFlags = ObjectFlags.ObjectLiteral;
|
||||
forEach(pattern.elements, e => {
|
||||
const name = e.propertyName || <Identifier>e.name;
|
||||
if (isComputedNonLiteralName(name)) {
|
||||
// do not include computed properties in the implied type
|
||||
objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties;
|
||||
return;
|
||||
}
|
||||
if (e.dotDotDotToken) {
|
||||
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
|
||||
return;
|
||||
}
|
||||
|
||||
const text = getTextOfPropertyName(name);
|
||||
const exprType = getLiteralTypeFromPropertyName(name);
|
||||
if (!isTypeUsableAsPropertyName(exprType)) {
|
||||
// do not include computed properties in the implied type
|
||||
objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties;
|
||||
return;
|
||||
}
|
||||
const text = getPropertyNameFromType(exprType);
|
||||
const flags = SymbolFlags.Property | (e.initializer ? SymbolFlags.Optional : 0);
|
||||
const symbol = createSymbol(flags, text);
|
||||
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
|
||||
@@ -5931,7 +5936,7 @@ namespace ts {
|
||||
function getBaseTypes(type: InterfaceType): BaseType[] {
|
||||
if (!type.resolvedBaseTypes) {
|
||||
if (type.objectFlags & ObjectFlags.Tuple) {
|
||||
type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters || emptyArray))];
|
||||
type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters || emptyArray), (<TupleType>type).readonly)];
|
||||
}
|
||||
else if (type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
|
||||
if (type.symbol.flags & SymbolFlags.Class) {
|
||||
@@ -6399,9 +6404,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether a type can be used as a late-bound name.
|
||||
* Indicates whether a type can be used as a property name.
|
||||
*/
|
||||
function isTypeUsableAsLateBoundName(type: Type): type is LiteralType | UniqueESSymbolType {
|
||||
function isTypeUsableAsPropertyName(type: Type): type is StringLiteralType | NumberLiteralType | UniqueESSymbolType {
|
||||
return !!(type.flags & TypeFlags.StringOrNumberLiteralOrUnique);
|
||||
}
|
||||
|
||||
@@ -6416,7 +6421,7 @@ namespace ts {
|
||||
function isLateBindableName(node: DeclarationName): node is LateBoundName {
|
||||
return isComputedPropertyName(node)
|
||||
&& isEntityNameExpression(node.expression)
|
||||
&& isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
|
||||
&& isTypeUsableAsPropertyName(checkComputedPropertyName(node));
|
||||
}
|
||||
|
||||
function isLateBoundName(name: __String): boolean {
|
||||
@@ -6448,11 +6453,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the symbolic name for a late-bound member from its type.
|
||||
* Gets the symbolic name for a member from its type.
|
||||
*/
|
||||
function getLateBoundNameFromType(type: StringLiteralType | NumberLiteralType | UniqueESSymbolType): __String {
|
||||
function getPropertyNameFromType(type: StringLiteralType | NumberLiteralType | UniqueESSymbolType): __String {
|
||||
if (type.flags & TypeFlags.UniqueESSymbol) {
|
||||
return `__@${type.symbol.escapedName}@${getSymbolId(type.symbol)}` as __String;
|
||||
return (<UniqueESSymbolType>type).escapedName;
|
||||
}
|
||||
if (type.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
|
||||
return escapeLeadingUnderscores("" + (<StringLiteralType | NumberLiteralType>type).value);
|
||||
@@ -6518,8 +6523,8 @@ namespace ts {
|
||||
// fall back to the early-bound name of this member.
|
||||
links.resolvedSymbol = decl.symbol;
|
||||
const type = checkComputedPropertyName(decl.name);
|
||||
if (isTypeUsableAsLateBoundName(type)) {
|
||||
const memberName = getLateBoundNameFromType(type);
|
||||
if (isTypeUsableAsPropertyName(type)) {
|
||||
const memberName = getPropertyNameFromType(type);
|
||||
const symbolFlags = decl.symbol.flags;
|
||||
|
||||
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
|
||||
@@ -7168,8 +7173,8 @@ namespace ts {
|
||||
const propType = instantiateType(templateType, templateMapper);
|
||||
// If the current iteration type constituent is a string literal type, create a property.
|
||||
// Otherwise, for type string create a string index signature.
|
||||
if (t.flags & TypeFlags.StringOrNumberLiteralOrUnique) {
|
||||
const propName = getLateBoundNameFromType(t as LiteralType);
|
||||
if (isTypeUsableAsPropertyName(t)) {
|
||||
const propName = getPropertyNameFromType(t);
|
||||
const modifiersProp = getPropertyOfType(modifiersType, propName);
|
||||
const isOptional = !!(templateModifiers & MappedTypeModifiers.IncludeOptional ||
|
||||
!(templateModifiers & MappedTypeModifiers.ExcludeOptional) && modifiersProp && modifiersProp.flags & SymbolFlags.Optional);
|
||||
@@ -7354,7 +7359,8 @@ namespace ts {
|
||||
function isTypeInvalidDueToUnionDiscriminant(contextualType: Type, obj: ObjectLiteralExpression | JsxAttributes): boolean {
|
||||
const list = obj.properties as NodeArray<ObjectLiteralElementLike | JsxAttributeLike>;
|
||||
return list.some(property => {
|
||||
const name = property.name && getTextOfPropertyName(property.name);
|
||||
const nameType = property.name && getLiteralTypeFromPropertyName(property.name);
|
||||
const name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
|
||||
const expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
|
||||
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
|
||||
});
|
||||
@@ -7520,6 +7526,7 @@ namespace ts {
|
||||
// very high likelyhood we're dealing with an infinite generic type that perpetually generates
|
||||
// new type identities as we descend into it. We stop the recursion here and mark this type
|
||||
// and the outer types as having circular constraints.
|
||||
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
|
||||
nonTerminating = true;
|
||||
return t.immediateBaseConstraint = noConstraintType;
|
||||
}
|
||||
@@ -7638,7 +7645,7 @@ namespace ts {
|
||||
const typeVariable = getHomomorphicTypeVariable(type);
|
||||
if (typeVariable) {
|
||||
const constraint = getConstraintOfTypeParameter(typeVariable);
|
||||
if (constraint && (isArrayType(constraint) || isReadonlyArrayType(constraint) || isTupleType(constraint))) {
|
||||
if (constraint && (isArrayType(constraint) || isTupleType(constraint))) {
|
||||
const mapper = makeUnaryTypeMapper(typeVariable, constraint);
|
||||
return instantiateType(type, combineTypeMappers(mapper, type.mapper));
|
||||
}
|
||||
@@ -9035,22 +9042,22 @@ namespace ts {
|
||||
return createTypeFromGenericGlobalType(getGlobalIterableIteratorType(/*reportErrors*/ true), [iteratedType]);
|
||||
}
|
||||
|
||||
function createArrayType(elementType: Type): ObjectType {
|
||||
return createTypeFromGenericGlobalType(globalArrayType, [elementType]);
|
||||
}
|
||||
|
||||
function createReadonlyArrayType(elementType: Type): ObjectType {
|
||||
return createTypeFromGenericGlobalType(globalReadonlyArrayType, [elementType]);
|
||||
function createArrayType(elementType: Type, readonly?: boolean): ObjectType {
|
||||
return createTypeFromGenericGlobalType(readonly ? globalReadonlyArrayType : globalArrayType, [elementType]);
|
||||
}
|
||||
|
||||
function getTypeFromArrayTypeNode(node: ArrayTypeNode): Type {
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType));
|
||||
links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType), isReadonlyTypeOperator(node.parent));
|
||||
}
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function isReadonlyTypeOperator(node: Node) {
|
||||
return isTypeOperatorNode(node) && node.operator === SyntaxKind.ReadonlyKeyword;
|
||||
}
|
||||
|
||||
// We represent tuple types as type references to synthesized generic interface types created by
|
||||
// this function. The types are of the form:
|
||||
//
|
||||
@@ -9058,7 +9065,7 @@ namespace ts {
|
||||
//
|
||||
// Note that the generic type created by this function has no symbol associated with it. The same
|
||||
// is true for each of the synthesized type parameters.
|
||||
function createTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, associatedNames: __String[] | undefined): TupleType {
|
||||
function createTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, readonly: boolean, associatedNames: __String[] | undefined): TupleType {
|
||||
let typeParameters: TypeParameter[] | undefined;
|
||||
const properties: Symbol[] = [];
|
||||
const maxLength = hasRestElement ? arity - 1 : arity;
|
||||
@@ -9067,7 +9074,8 @@ namespace ts {
|
||||
for (let i = 0; i < arity; i++) {
|
||||
const typeParameter = typeParameters[i] = createTypeParameter();
|
||||
if (i < maxLength) {
|
||||
const property = createSymbol(SymbolFlags.Property | (i >= minLength ? SymbolFlags.Optional : 0), "" + i as __String);
|
||||
const property = createSymbol(SymbolFlags.Property | (i >= minLength ? SymbolFlags.Optional : 0),
|
||||
"" + i as __String, readonly ? CheckFlags.Readonly : 0);
|
||||
property.type = typeParameter;
|
||||
properties.push(property);
|
||||
}
|
||||
@@ -9096,25 +9104,26 @@ namespace ts {
|
||||
type.declaredNumberIndexInfo = undefined;
|
||||
type.minLength = minLength;
|
||||
type.hasRestElement = hasRestElement;
|
||||
type.readonly = readonly;
|
||||
type.associatedNames = associatedNames;
|
||||
return type;
|
||||
}
|
||||
|
||||
function getTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, associatedNames?: __String[]): GenericType {
|
||||
const key = arity + (hasRestElement ? "+" : ",") + minLength + (associatedNames && associatedNames.length ? "," + associatedNames.join(",") : "");
|
||||
function getTupleTypeOfArity(arity: number, minLength: number, hasRestElement: boolean, readonly: boolean, associatedNames?: __String[]): GenericType {
|
||||
const key = arity + (hasRestElement ? "+" : ",") + minLength + (readonly ? "R" : "") + (associatedNames && associatedNames.length ? "," + associatedNames.join(",") : "");
|
||||
let type = tupleTypes.get(key);
|
||||
if (!type) {
|
||||
tupleTypes.set(key, type = createTupleTypeOfArity(arity, minLength, hasRestElement, associatedNames));
|
||||
tupleTypes.set(key, type = createTupleTypeOfArity(arity, minLength, hasRestElement, readonly, associatedNames));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
function createTupleType(elementTypes: ReadonlyArray<Type>, minLength = elementTypes.length, hasRestElement = false, associatedNames?: __String[]) {
|
||||
function createTupleType(elementTypes: ReadonlyArray<Type>, minLength = elementTypes.length, hasRestElement = false, readonly = false, associatedNames?: __String[]) {
|
||||
const arity = elementTypes.length;
|
||||
if (arity === 1 && hasRestElement) {
|
||||
return createArrayType(elementTypes[0]);
|
||||
}
|
||||
const tupleType = getTupleTypeOfArity(arity, minLength, arity > 0 && hasRestElement, associatedNames);
|
||||
const tupleType = getTupleTypeOfArity(arity, minLength, arity > 0 && hasRestElement, readonly, associatedNames);
|
||||
return elementTypes.length ? createTypeReference(tupleType, elementTypes) : tupleType;
|
||||
}
|
||||
|
||||
@@ -9128,7 +9137,7 @@ namespace ts {
|
||||
const type = getTypeFromTypeNode(n);
|
||||
return n === restElement && getIndexTypeOfType(type, IndexKind.Number) || type;
|
||||
});
|
||||
links.resolvedType = createTupleType(elementTypes, minLength, !!restElement);
|
||||
links.resolvedType = createTupleType(elementTypes, minLength, !!restElement, isReadonlyTypeOperator(node.parent));
|
||||
}
|
||||
return links.resolvedType;
|
||||
}
|
||||
@@ -9143,6 +9152,7 @@ namespace ts {
|
||||
(type.typeArguments || emptyArray).slice(index),
|
||||
Math.max(0, tuple.minLength - index),
|
||||
tuple.hasRestElement,
|
||||
tuple.readonly,
|
||||
tuple.associatedNames && tuple.associatedNames.slice(index),
|
||||
);
|
||||
}
|
||||
@@ -9232,18 +9242,6 @@ namespace ts {
|
||||
return includes;
|
||||
}
|
||||
|
||||
function isSubtypeOfAny(source: Type, targets: ReadonlyArray<Type>): boolean {
|
||||
for (const target of targets) {
|
||||
if (source !== target && isTypeSubtypeOf(source, target) && (
|
||||
!(getObjectFlags(getTargetType(source)) & ObjectFlags.Class) ||
|
||||
!(getObjectFlags(getTargetType(target)) & ObjectFlags.Class) ||
|
||||
isTypeDerivedFrom(source, target))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSetOfLiteralsFromSameEnum(types: ReadonlyArray<Type>): boolean {
|
||||
const first = types[0];
|
||||
if (first.flags & TypeFlags.EnumLiteral) {
|
||||
@@ -9260,17 +9258,42 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function removeSubtypes(types: Type[]) {
|
||||
if (types.length === 0 || isSetOfLiteralsFromSameEnum(types)) {
|
||||
return;
|
||||
function removeSubtypes(types: Type[], primitivesOnly: boolean): boolean {
|
||||
const len = types.length;
|
||||
if (len === 0 || isSetOfLiteralsFromSameEnum(types)) {
|
||||
return true;
|
||||
}
|
||||
let i = types.length;
|
||||
let i = len;
|
||||
let count = 0;
|
||||
while (i > 0) {
|
||||
i--;
|
||||
if (isSubtypeOfAny(types[i], types)) {
|
||||
orderedRemoveItemAt(types, i);
|
||||
const source = types[i];
|
||||
for (const target of types) {
|
||||
if (source !== target) {
|
||||
if (count === 10000) {
|
||||
// After 10000 subtype checks we estimate the remaining amount of work by assuming the
|
||||
// same ratio of checks to removals. If the estimated number of remaining type checks is
|
||||
// greater than an upper limit we deem the union type too complex to represent. The
|
||||
// upper limit is 25M for unions of primitives only, and 1M otherwise. This for example
|
||||
// caps union types at 5000 unique literal types and 1000 unique object types.
|
||||
const estimatedCount = (count / (len - i)) * len;
|
||||
if (estimatedCount > (primitivesOnly ? 25000000 : 1000000)) {
|
||||
error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
if (isTypeSubtypeOf(source, target) && (
|
||||
!(getObjectFlags(getTargetType(source)) & ObjectFlags.Class) ||
|
||||
!(getObjectFlags(getTargetType(target)) & ObjectFlags.Class) ||
|
||||
isTypeDerivedFrom(source, target))) {
|
||||
orderedRemoveItemAt(types, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags) {
|
||||
@@ -9317,7 +9340,9 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
case UnionReduction.Subtype:
|
||||
removeSubtypes(typeSet);
|
||||
if (!removeSubtypes(typeSet, !(includes & TypeFlags.StructuredOrInstantiable))) {
|
||||
return errorType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (typeSet.length === 0) {
|
||||
@@ -9680,6 +9705,9 @@ namespace ts {
|
||||
? getESSymbolLikeTypeForNode(walkUpParenthesizedTypes(node.parent))
|
||||
: errorType;
|
||||
break;
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
links.resolvedType = getTypeFromTypeNode(node.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return links.resolvedType!; // TODO: GH#18217
|
||||
@@ -9722,8 +9750,8 @@ namespace ts {
|
||||
|
||||
function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, cacheSymbol: boolean, missingType: Type) {
|
||||
const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined;
|
||||
const propName = isTypeUsableAsLateBoundName(indexType) ?
|
||||
getLateBoundNameFromType(indexType) :
|
||||
const propName = isTypeUsableAsPropertyName(indexType) ?
|
||||
getPropertyNameFromType(indexType) :
|
||||
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
|
||||
getPropertyNameForKnownSymbolName(idText((<PropertyAccessExpression>accessExpression.argumentExpression).name)) :
|
||||
accessNode && isPropertyName(accessNode) ?
|
||||
@@ -10413,6 +10441,7 @@ namespace ts {
|
||||
function createUniqueESSymbolType(symbol: Symbol) {
|
||||
const type = <UniqueESSymbolType>createType(TypeFlags.UniqueESSymbol);
|
||||
type.symbol = symbol;
|
||||
type.escapedName = `__@${type.symbol.escapedName}@${getSymbolId(type.symbol)}` as __String;
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -10633,7 +10662,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getRestrictiveTypeParameter(tp: TypeParameter) {
|
||||
return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
|
||||
return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (
|
||||
tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
|
||||
(tp.restrictiveInstantiation as TypeParameter).constraint = unknownType,
|
||||
tp.restrictiveInstantiation
|
||||
);
|
||||
}
|
||||
|
||||
function restrictiveMapper(type: Type) {
|
||||
@@ -10707,7 +10740,7 @@ namespace ts {
|
||||
}
|
||||
// Keep the flags from the symbol we're instantiating. Mark that is instantiated, and
|
||||
// also transient so that we can just store data on it directly.
|
||||
const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | getCheckFlags(symbol) & (CheckFlags.Late | CheckFlags.OptionalParameter | CheckFlags.RestParameter));
|
||||
const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | getCheckFlags(symbol) & (CheckFlags.Readonly | CheckFlags.Late | CheckFlags.OptionalParameter | CheckFlags.RestParameter));
|
||||
result.declarations = symbol.declarations;
|
||||
result.parent = symbol.parent;
|
||||
result.target = symbol;
|
||||
@@ -10838,11 +10871,11 @@ namespace ts {
|
||||
return errorType;
|
||||
}
|
||||
type.instantiating = true;
|
||||
const modifiers = getMappedTypeModifiers(type);
|
||||
const result = mapType(mappedTypeVariable, t => {
|
||||
if (t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.InstantiableNonPrimitive | TypeFlags.Object | TypeFlags.Intersection) && t !== wildcardType) {
|
||||
const replacementMapper = createReplacementMapper(typeVariable, t, mapper);
|
||||
return isArrayType(t) ? createArrayType(instantiateMappedTypeTemplate(type, numberType, /*isOptional*/ true, replacementMapper)) :
|
||||
isReadonlyArrayType(t) ? createReadonlyArrayType(instantiateMappedTypeTemplate(type, numberType, /*isOptional*/ true, replacementMapper)) :
|
||||
return isArrayType(t) ? createArrayType(instantiateMappedTypeTemplate(type, numberType, /*isOptional*/ true, replacementMapper), getModifiedReadonlyState(isReadonlyArrayType(t), modifiers)) :
|
||||
isTupleType(t) ? instantiateMappedTupleType(t, type, replacementMapper) :
|
||||
instantiateAnonymousType(type, replacementMapper);
|
||||
}
|
||||
@@ -10855,6 +10888,10 @@ namespace ts {
|
||||
return instantiateAnonymousType(type, mapper);
|
||||
}
|
||||
|
||||
function getModifiedReadonlyState(state: boolean, modifiers: MappedTypeModifiers) {
|
||||
return modifiers & MappedTypeModifiers.IncludeReadonly ? true : modifiers & MappedTypeModifiers.ExcludeReadonly ? false : state;
|
||||
}
|
||||
|
||||
function instantiateMappedTupleType(tupleType: TupleTypeReference, mappedType: MappedType, mapper: TypeMapper) {
|
||||
const minLength = tupleType.target.minLength;
|
||||
const elementTypes = map(tupleType.typeArguments || emptyArray, (_, i) =>
|
||||
@@ -10863,7 +10900,8 @@ namespace ts {
|
||||
const newMinLength = modifiers & MappedTypeModifiers.IncludeOptional ? 0 :
|
||||
modifiers & MappedTypeModifiers.ExcludeOptional ? getTypeReferenceArity(tupleType) - (tupleType.target.hasRestElement ? 1 : 0) :
|
||||
minLength;
|
||||
return createTupleType(elementTypes, newMinLength, tupleType.target.hasRestElement, tupleType.target.associatedNames);
|
||||
const newReadonly = getModifiedReadonlyState(tupleType.target.readonly, modifiers);
|
||||
return createTupleType(elementTypes, newMinLength, tupleType.target.hasRestElement, newReadonly, tupleType.target.associatedNames);
|
||||
}
|
||||
|
||||
function instantiateMappedTypeTemplate(type: MappedType, key: Type, isOptional: boolean, mapper: TypeMapper) {
|
||||
@@ -10936,6 +10974,7 @@ namespace ts {
|
||||
// We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
|
||||
// with a combination of infinite generic types that perpetually generate new type identities. We stop
|
||||
// the recursion here by yielding the error type.
|
||||
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
|
||||
return errorType;
|
||||
}
|
||||
instantiationDepth++;
|
||||
@@ -11300,7 +11339,7 @@ namespace ts {
|
||||
}
|
||||
if (resultObj.error) {
|
||||
const reportedDiag = resultObj.error;
|
||||
const propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
|
||||
const propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
|
||||
const targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
|
||||
|
||||
let issuedElaboration = false;
|
||||
@@ -12725,7 +12764,7 @@ namespace ts {
|
||||
errorInfo = saveErrorInfo;
|
||||
}
|
||||
}
|
||||
else if (isTupleType(source) && (isArrayType(target) || isReadonlyArrayType(target)) || isArrayType(source) && isReadonlyArrayType(target)) {
|
||||
else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
|
||||
return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors);
|
||||
}
|
||||
// Even if relationship doesn't hold for unions, intersections, or generic type references,
|
||||
@@ -13266,11 +13305,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getVariances(type: GenericType): Variance[] {
|
||||
if (!strictFunctionTypes) {
|
||||
return emptyArray;
|
||||
}
|
||||
if (type === globalArrayType || type === globalReadonlyArrayType) {
|
||||
// Arrays are known to be covariant, no need to spend time computing this (emptyArray implies covariance for all parameters)
|
||||
// Arrays and tuples are known to be covariant, no need to spend time computing this (emptyArray implies covariance for all parameters)
|
||||
if (!strictFunctionTypes || type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||
return emptyArray;
|
||||
}
|
||||
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
|
||||
@@ -13560,7 +13596,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isArrayType(type: Type): boolean {
|
||||
return !!(getObjectFlags(type) & ObjectFlags.Reference) && (<TypeReference>type).target === globalArrayType;
|
||||
return !!(getObjectFlags(type) & ObjectFlags.Reference) && ((<TypeReference>type).target === globalArrayType || (<TypeReference>type).target === globalReadonlyArrayType);
|
||||
}
|
||||
|
||||
function isReadonlyArrayType(type: Type): boolean {
|
||||
@@ -13574,8 +13610,7 @@ namespace ts {
|
||||
function isArrayLikeType(type: Type): boolean {
|
||||
// A type is array-like if it is a reference to the global Array or global ReadonlyArray type,
|
||||
// or if it is not the undefined or null type and if it is assignable to ReadonlyArray<any>
|
||||
return getObjectFlags(type) & ObjectFlags.Reference && ((<TypeReference>type).target === globalArrayType || (<TypeReference>type).target === globalReadonlyArrayType) ||
|
||||
!(type.flags & TypeFlags.Nullable) && isTypeAssignableTo(type, anyReadonlyArrayType);
|
||||
return isArrayType(type) || !(type.flags & TypeFlags.Nullable) && isTypeAssignableTo(type, anyReadonlyArrayType);
|
||||
}
|
||||
|
||||
function isEmptyArrayLiteralType(type: Type): boolean {
|
||||
@@ -14184,16 +14219,13 @@ namespace ts {
|
||||
// For arrays and tuples we infer new arrays and tuples where the reverse mapping has been
|
||||
// applied to the element type(s).
|
||||
if (isArrayType(source)) {
|
||||
return createArrayType(inferReverseMappedType((<TypeReference>source).typeArguments![0], target, constraint));
|
||||
}
|
||||
if (isReadonlyArrayType(source)) {
|
||||
return createReadonlyArrayType(inferReverseMappedType((<TypeReference>source).typeArguments![0], target, constraint));
|
||||
return createArrayType(inferReverseMappedType((<TypeReference>source).typeArguments![0], target, constraint), isReadonlyArrayType(source));
|
||||
}
|
||||
if (isTupleType(source)) {
|
||||
const elementTypes = map(source.typeArguments || emptyArray, t => inferReverseMappedType(t, target, constraint));
|
||||
const minLength = getMappedTypeModifiers(target) & MappedTypeModifiers.IncludeOptional ?
|
||||
getTypeReferenceArity(source) - (source.target.hasRestElement ? 1 : 0) : source.target.minLength;
|
||||
return createTupleType(elementTypes, minLength, source.target.hasRestElement, source.target.associatedNames);
|
||||
return createTupleType(elementTypes, minLength, source.target.hasRestElement, source.target.readonly, source.target.associatedNames);
|
||||
}
|
||||
// For all other object types we infer a new object type where the reverse mapping has been
|
||||
// applied to the type of each property.
|
||||
@@ -14567,7 +14599,12 @@ namespace ts {
|
||||
priority |= InferencePriority.MappedTypeConstraint;
|
||||
inferFromTypes(getIndexType(source), constraintType);
|
||||
priority = savePriority;
|
||||
inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(<MappedType>target));
|
||||
const valueTypes = compact([
|
||||
getIndexTypeOfType(source, IndexKind.String),
|
||||
getIndexTypeOfType(source, IndexKind.Number),
|
||||
...map(getPropertiesOfType(source), getTypeOfSymbol)
|
||||
]);
|
||||
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(<MappedType>target));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -15172,7 +15209,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getTypeOfDestructuredProperty(type: Type, name: PropertyName) {
|
||||
const text = getTextOfPropertyName(name);
|
||||
const nameType = getLiteralTypeFromPropertyName(name);
|
||||
if (!isTypeUsableAsPropertyName(nameType)) return errorType;
|
||||
const text = getPropertyNameFromType(nameType);
|
||||
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
|
||||
isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) ||
|
||||
getIndexTypeOfType(type, IndexKind.String) ||
|
||||
@@ -16018,6 +16057,15 @@ namespace ts {
|
||||
assumeTrue = !assumeTrue;
|
||||
}
|
||||
const valueType = getTypeOfExpression(value);
|
||||
if ((type.flags & TypeFlags.Unknown) && (operator === SyntaxKind.EqualsEqualsEqualsToken) && assumeTrue) {
|
||||
if (valueType.flags & (TypeFlags.Primitive | TypeFlags.NonPrimitive)) {
|
||||
return valueType;
|
||||
}
|
||||
if (valueType.flags & TypeFlags.Object) {
|
||||
return nonPrimitiveType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
if (valueType.flags & TypeFlags.Nullable) {
|
||||
if (!strictNullChecks) {
|
||||
return type;
|
||||
@@ -17304,9 +17352,10 @@ namespace ts {
|
||||
const parentDeclaration = declaration.parent.parent;
|
||||
const name = declaration.propertyName || declaration.name;
|
||||
const parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
|
||||
if (parentType && !isBindingPattern(name)) {
|
||||
const text = getTextOfPropertyName(name);
|
||||
if (text !== undefined) {
|
||||
if (parentType && !isBindingPattern(name) && !isComputedNonLiteralName(name)) {
|
||||
const nameType = getLiteralTypeFromPropertyName(name);
|
||||
if (isTypeUsableAsPropertyName(nameType)) {
|
||||
const text = getPropertyNameFromType(nameType);
|
||||
return getTypeOfPropertyOfType(parentType, text);
|
||||
}
|
||||
}
|
||||
@@ -18092,7 +18141,9 @@ namespace ts {
|
||||
return createTupleType(elementTypes, minLength, hasRestElement);
|
||||
}
|
||||
}
|
||||
return getArrayLiteralType(elementTypes, UnionReduction.Subtype);
|
||||
return createArrayType(elementTypes.length ?
|
||||
getUnionType(elementTypes, UnionReduction.Subtype) :
|
||||
strictNullChecks ? implicitNeverType : undefinedWideningType);
|
||||
}
|
||||
|
||||
function getArrayLiteralTupleTypeIfApplicable(elementTypes: Type[], contextualType: Type | undefined, hasRestElement: boolean, elementCount = elementTypes.length) {
|
||||
@@ -18121,12 +18172,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getArrayLiteralType(elementTypes: Type[], unionReduction = UnionReduction.Literal) {
|
||||
return createArrayType(elementTypes.length ?
|
||||
getUnionType(elementTypes, unionReduction) :
|
||||
strictNullChecks ? implicitNeverType : undefinedWideningType);
|
||||
}
|
||||
|
||||
function isNumericName(name: DeclarationName): boolean {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
@@ -18263,10 +18308,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
typeFlags |= type.flags;
|
||||
const nameType = computedNameType && computedNameType.flags & TypeFlags.StringOrNumberLiteralOrUnique ?
|
||||
<LiteralType | UniqueESSymbolType>computedNameType : undefined;
|
||||
const nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
|
||||
const prop = nameType ?
|
||||
createSymbol(SymbolFlags.Property | member.flags, getLateBoundNameFromType(nameType), CheckFlags.Late) :
|
||||
createSymbol(SymbolFlags.Property | member.flags, getPropertyNameFromType(nameType), CheckFlags.Late) :
|
||||
createSymbol(SymbolFlags.Property | member.flags, member.escapedName);
|
||||
if (nameType) {
|
||||
prop.nameType = nameType;
|
||||
@@ -21409,7 +21453,7 @@ namespace ts {
|
||||
}
|
||||
const minArgumentCount = getMinArgumentCount(source);
|
||||
const minLength = minArgumentCount < start ? 0 : minArgumentCount - start;
|
||||
return createTupleType(types, minLength, !!restType, names);
|
||||
return createTupleType(types, minLength, !!restType, /*readonly*/ false, names);
|
||||
}
|
||||
|
||||
function getParameterCount(signature: Signature) {
|
||||
@@ -22315,15 +22359,15 @@ namespace ts {
|
||||
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: NodeArray<ObjectLiteralElementLike>, rightIsThis = false) {
|
||||
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
const name = property.name;
|
||||
const text = getTextOfPropertyName(name);
|
||||
if (text) {
|
||||
const exprType = getLiteralTypeFromPropertyName(name);
|
||||
if (isTypeUsableAsPropertyName(exprType)) {
|
||||
const text = getPropertyNameFromType(exprType);
|
||||
const prop = getPropertyOfType(objectLiteralType, text);
|
||||
if (prop) {
|
||||
markPropertyAsReferenced(prop, property, rightIsThis);
|
||||
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
|
||||
}
|
||||
}
|
||||
const exprType = getLiteralTypeFromPropertyName(name);
|
||||
const elementType = getIndexedAccessType(objectLiteralType, exprType, name);
|
||||
const type = getFlowTypeOfDestructuring(property, elementType);
|
||||
return checkDestructuringAssignment(property.kind === SyntaxKind.ShorthandPropertyAssignment ? property : property.initializer, type);
|
||||
@@ -23046,7 +23090,7 @@ namespace ts {
|
||||
return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
|
||||
}
|
||||
|
||||
function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration, type: Type, checkMode?: CheckMode) {
|
||||
function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration | QualifiedName, type: Type, checkMode?: CheckMode) {
|
||||
if (checkMode === CheckMode.Inferential) {
|
||||
const signature = getSingleCallSignature(type);
|
||||
if (signature && signature.typeParameters) {
|
||||
@@ -23116,15 +23160,10 @@ namespace ts {
|
||||
// have the wildcard function type; this form of type check is used during overload resolution to exclude
|
||||
// contextually typed function and arrow expressions in the initial phase.
|
||||
function checkExpression(node: Expression | QualifiedName, checkMode?: CheckMode, forceTuple?: boolean): Type {
|
||||
let type: Type;
|
||||
if (node.kind === SyntaxKind.QualifiedName) {
|
||||
type = checkQualifiedName(<QualifiedName>node);
|
||||
}
|
||||
else {
|
||||
const uninstantiatedType = checkExpressionWorker(node, checkMode, forceTuple);
|
||||
type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
|
||||
}
|
||||
|
||||
const saveCurrentNode = currentNode;
|
||||
currentNode = node;
|
||||
const uninstantiatedType = checkExpressionWorker(node, checkMode, forceTuple);
|
||||
const type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
|
||||
if (isConstEnumObjectType(type)) {
|
||||
// enum object type for const enums are only permitted in:
|
||||
// - 'left' in property access
|
||||
@@ -23140,6 +23179,7 @@ namespace ts {
|
||||
error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query);
|
||||
}
|
||||
}
|
||||
currentNode = saveCurrentNode;
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -23151,7 +23191,7 @@ namespace ts {
|
||||
return checkExpression(node.expression, checkMode);
|
||||
}
|
||||
|
||||
function checkExpressionWorker(node: Expression, checkMode: CheckMode | undefined, forceTuple?: boolean): Type {
|
||||
function checkExpressionWorker(node: Expression | QualifiedName, checkMode: CheckMode | undefined, forceTuple?: boolean): Type {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return checkIdentifier(<Identifier>node);
|
||||
@@ -23184,6 +23224,8 @@ namespace ts {
|
||||
return checkObjectLiteral(<ObjectLiteralExpression>node, checkMode);
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return checkPropertyAccessExpression(<PropertyAccessExpression>node);
|
||||
case SyntaxKind.QualifiedName:
|
||||
return checkQualifiedName(<QualifiedName>node);
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
return checkIndexedAccess(<ElementAccessExpression>node);
|
||||
case SyntaxKind.CallExpression:
|
||||
@@ -23307,7 +23349,7 @@ namespace ts {
|
||||
|
||||
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are
|
||||
// not allowed in a rest parameter, we already have an error from checkGrammarParameterList.
|
||||
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isTypeAssignableTo(getTypeOfSymbol(node.symbol), anyArrayType)) {
|
||||
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isTypeAssignableTo(getTypeOfSymbol(node.symbol), anyReadonlyArrayType)) {
|
||||
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
|
||||
}
|
||||
}
|
||||
@@ -25638,13 +25680,14 @@ namespace ts {
|
||||
const parent = node.parent.parent;
|
||||
const parentType = getTypeForBindingElementParent(parent);
|
||||
const name = node.propertyName || node.name;
|
||||
if (!isBindingPattern(name)) {
|
||||
const nameText = getTextOfPropertyName(name);
|
||||
if (nameText) {
|
||||
const property = getPropertyOfType(parentType!, nameText); // TODO: GH#18217
|
||||
if (!isBindingPattern(name) && parentType) {
|
||||
const exprType = getLiteralTypeFromPropertyName(name);
|
||||
if (isTypeUsableAsPropertyName(exprType)) {
|
||||
const nameText = getPropertyNameFromType(exprType);
|
||||
const property = getPropertyOfType(parentType, nameText);
|
||||
if (property) {
|
||||
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
|
||||
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === SyntaxKind.SuperKeyword, parentType!, property);
|
||||
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === SyntaxKind.SuperKeyword, parentType, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27864,10 +27907,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkSourceElement(node: Node | undefined): void {
|
||||
if (!node) {
|
||||
return;
|
||||
if (node) {
|
||||
const saveCurrentNode = currentNode;
|
||||
currentNode = node;
|
||||
checkSourceElementWorker(node);
|
||||
currentNode = saveCurrentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function checkSourceElementWorker(node: Node): void {
|
||||
if (isInJSFile(node)) {
|
||||
forEach((node as JSDocContainer).jsDoc, ({ tags }) => forEach(tags, checkSourceElement));
|
||||
}
|
||||
@@ -28125,32 +28173,36 @@ namespace ts {
|
||||
|
||||
function checkDeferredNodes(context: SourceFile) {
|
||||
const links = getNodeLinks(context);
|
||||
if (!links.deferredNodes) {
|
||||
return;
|
||||
if (links.deferredNodes) {
|
||||
links.deferredNodes.forEach(checkDeferredNode);
|
||||
}
|
||||
links.deferredNodes.forEach(node => {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
checkFunctionExpressionOrObjectLiteralMethodDeferred(<FunctionExpression>node);
|
||||
break;
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
checkAccessorDeclaration(<AccessorDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.ClassExpression:
|
||||
checkClassExpressionDeferred(<ClassExpression>node);
|
||||
break;
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
checkJsxSelfClosingElementDeferred(<JsxSelfClosingElement>node);
|
||||
break;
|
||||
case SyntaxKind.JsxElement:
|
||||
checkJsxElementDeferred(<JsxElement>node);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkDeferredNode(node: Node) {
|
||||
const saveCurrentNode = currentNode;
|
||||
currentNode = node;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
checkFunctionExpressionOrObjectLiteralMethodDeferred(<FunctionExpression>node);
|
||||
break;
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
checkAccessorDeclaration(<AccessorDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.ClassExpression:
|
||||
checkClassExpressionDeferred(<ClassExpression>node);
|
||||
break;
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
checkJsxSelfClosingElementDeferred(<JsxSelfClosingElement>node);
|
||||
break;
|
||||
case SyntaxKind.JsxElement:
|
||||
checkJsxElementDeferred(<JsxElement>node);
|
||||
break;
|
||||
}
|
||||
currentNode = saveCurrentNode;
|
||||
}
|
||||
|
||||
function checkSourceFile(node: SourceFile) {
|
||||
@@ -30653,6 +30705,11 @@ namespace ts {
|
||||
return grammarErrorOnNode(node, Diagnostics.unique_symbol_types_are_not_allowed_here);
|
||||
}
|
||||
}
|
||||
else if (node.operator === SyntaxKind.ReadonlyKeyword) {
|
||||
if (node.type.kind !== SyntaxKind.ArrayType && node.type.kind !== SyntaxKind.TupleType) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.readonly_type_modifier_is_only_permitted_on_array_and_tuple_types, tokenToString(SyntaxKind.SymbolKeyword));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarForInvalidDynamicName(node: DeclarationName, message: DiagnosticMessage) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ts {
|
||||
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
|
||||
// If changing the text in this section, be sure to test `configureNightly` too.
|
||||
export const versionMajorMinor = "3.3";
|
||||
export const versionMajorMinor = "3.4";
|
||||
/** The version of the TypeScript compiler release */
|
||||
export const version = `${versionMajorMinor}.0-dev`;
|
||||
}
|
||||
@@ -884,8 +884,11 @@ namespace ts {
|
||||
/**
|
||||
* Compacts an array, removing any falsey elements.
|
||||
*/
|
||||
export function compact<T>(array: T[]): T[];
|
||||
export function compact<T>(array: ReadonlyArray<T>): ReadonlyArray<T>;
|
||||
export function compact<T>(array: (T | undefined | null | false | 0 | "")[]): T[];
|
||||
export function compact<T>(array: ReadonlyArray<T | undefined | null | false | 0 | "">): ReadonlyArray<T>;
|
||||
// TSLint thinks these can be combined with the above - they cannot; they'd produce higher-priority inferences and prevent the falsey types from being stripped
|
||||
export function compact<T>(array: T[]): T[]; // tslint:disable-line unified-signatures
|
||||
export function compact<T>(array: ReadonlyArray<T>): ReadonlyArray<T>; // tslint:disable-line unified-signatures
|
||||
export function compact<T>(array: T[]): T[] {
|
||||
let result: T[] | undefined;
|
||||
if (array) {
|
||||
|
||||
@@ -1023,6 +1023,10 @@
|
||||
"category": "Error",
|
||||
"code": 1353
|
||||
},
|
||||
"'readonly' type modifier is only permitted on array and tuple types.": {
|
||||
"category": "Error",
|
||||
"code": 1354
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
@@ -2128,6 +2132,14 @@
|
||||
"category": "Error",
|
||||
"code": 2588
|
||||
},
|
||||
"Type instantiation is excessively deep and possibly infinite.": {
|
||||
"category": "Error",
|
||||
"code": 2589
|
||||
},
|
||||
"Expression produces a union type that is too complex to represent.": {
|
||||
"category": "Error",
|
||||
"code": 2590
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
@@ -876,8 +876,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function createTypeOperatorNode(type: TypeNode): TypeOperatorNode;
|
||||
export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword, type: TypeNode): TypeOperatorNode;
|
||||
export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | TypeNode, type?: TypeNode) {
|
||||
export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode;
|
||||
export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | TypeNode, type?: TypeNode) {
|
||||
const node = createSynthesizedNode(SyntaxKind.TypeOperator) as TypeOperatorNode;
|
||||
node.operator = typeof operatorOrType === "number" ? operatorOrType : SyntaxKind.KeyOfKeyword;
|
||||
node.type = parenthesizeElementTypeMember(typeof operatorOrType === "number" ? type! : operatorOrType);
|
||||
|
||||
@@ -2966,6 +2966,7 @@ namespace ts {
|
||||
case SyntaxKind.NumberKeyword:
|
||||
case SyntaxKind.BigIntKeyword:
|
||||
case SyntaxKind.BooleanKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.SymbolKeyword:
|
||||
case SyntaxKind.UniqueKeyword:
|
||||
case SyntaxKind.VoidKeyword:
|
||||
@@ -3055,7 +3056,7 @@ namespace ts {
|
||||
return finishNode(postfix);
|
||||
}
|
||||
|
||||
function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword) {
|
||||
function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {
|
||||
const node = <TypeOperatorNode>createNode(SyntaxKind.TypeOperator);
|
||||
parseExpected(operator);
|
||||
node.operator = operator;
|
||||
@@ -3077,6 +3078,7 @@ namespace ts {
|
||||
switch (operator) {
|
||||
case SyntaxKind.KeyOfKeyword:
|
||||
case SyntaxKind.UniqueKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
return parseTypeOperator(operator);
|
||||
case SyntaxKind.InferKeyword:
|
||||
return parseInferType();
|
||||
|
||||
@@ -663,8 +663,15 @@ namespace ts {
|
||||
let pendingKind!: CommentKind;
|
||||
let pendingHasTrailingNewLine!: boolean;
|
||||
let hasPendingCommentRange = false;
|
||||
let collecting = trailing || pos === 0;
|
||||
let collecting = trailing;
|
||||
let accumulator = initial;
|
||||
if (pos === 0) {
|
||||
collecting = true;
|
||||
const shebang = getShebang(text);
|
||||
if (shebang) {
|
||||
pos = shebang.length;
|
||||
}
|
||||
}
|
||||
scan: while (pos >= 0 && pos < text.length) {
|
||||
const ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
|
||||
@@ -1934,8 +1934,13 @@ namespace ts {
|
||||
case SyntaxKind.ConditionalType:
|
||||
return serializeTypeList([(<ConditionalTypeNode>node).trueType, (<ConditionalTypeNode>node).falseType]);
|
||||
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.TypeOperator:
|
||||
if ((<TypeOperatorNode>node).operator === SyntaxKind.ReadonlyKeyword) {
|
||||
return serializeTypeNode((<TypeOperatorNode>node).type);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
|
||||
@@ -1234,7 +1234,7 @@ namespace ts {
|
||||
|
||||
export interface TypeOperatorNode extends TypeNode {
|
||||
kind: SyntaxKind.TypeOperator;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword;
|
||||
type: TypeNode;
|
||||
}
|
||||
|
||||
@@ -3974,6 +3974,7 @@ namespace ts {
|
||||
// Unique symbol types (TypeFlags.UniqueESSymbol)
|
||||
export interface UniqueESSymbolType extends Type {
|
||||
symbol: Symbol;
|
||||
escapedName: __String;
|
||||
}
|
||||
|
||||
export interface StringLiteralType extends LiteralType {
|
||||
@@ -4081,6 +4082,7 @@ namespace ts {
|
||||
export interface TupleType extends GenericType {
|
||||
minLength: number;
|
||||
hasRestElement: boolean;
|
||||
readonly: boolean;
|
||||
associatedNames?: __String[];
|
||||
}
|
||||
|
||||
|
||||
@@ -778,7 +778,8 @@ namespace ts {
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
return escapeLeadingUnderscores(name.text);
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return isStringOrNumericLiteralLike(name.expression) ? escapeLeadingUnderscores(name.expression.text) : undefined!; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
|
||||
if (isStringOrNumericLiteralLike(name.expression)) return escapeLeadingUnderscores(name.expression.text);
|
||||
return Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
|
||||
default:
|
||||
return Debug.assertNever(name);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
"compilerOptions": {
|
||||
"outFile": "../../built/local/run.js",
|
||||
"composite": false,
|
||||
@@ -43,6 +43,7 @@
|
||||
"unittests/asserts.ts",
|
||||
"unittests/base64.ts",
|
||||
"unittests/builder.ts",
|
||||
"unittests/comments.ts",
|
||||
"unittests/compilerCore.ts",
|
||||
"unittests/convertToBase64.ts",
|
||||
"unittests/customTransforms.ts",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace ts {
|
||||
describe("comment parsing", () => {
|
||||
const withShebang = `#! node
|
||||
/** comment */
|
||||
// another one
|
||||
;`;
|
||||
const noShebang = `/** comment */
|
||||
// another one
|
||||
;`;
|
||||
const withTrailing = `;/* comment */
|
||||
// another one
|
||||
`;
|
||||
it("skips shebang", () => {
|
||||
const result = getLeadingCommentRanges(withShebang, 0);
|
||||
assert.isDefined(result);
|
||||
assert.strictEqual(result!.length, 2);
|
||||
});
|
||||
|
||||
it("treats all comments at start of file as leading comments", () => {
|
||||
const result = getLeadingCommentRanges(noShebang, 0);
|
||||
assert.isDefined(result);
|
||||
assert.strictEqual(result!.length, 2);
|
||||
});
|
||||
|
||||
it("returns leading comments if position is not 0", () => {
|
||||
const result = getLeadingCommentRanges(withTrailing, 1);
|
||||
assert.isDefined(result);
|
||||
assert.strictEqual(result!.length, 1);
|
||||
assert.strictEqual(result![0].kind, SyntaxKind.SingleLineCommentTrivia);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
"compilerOptions": {
|
||||
"outFile": "../../built/local/tsc.js"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig-base",
|
||||
"compilerOptions": {
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"composite": false
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
|
||||
"compilerOptions": {
|
||||
"outFile": "../../built/local/tsserver.js",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
"compilerOptions": {
|
||||
"removeComments": true,
|
||||
"outFile": "../../built/local/typingsInstaller.js",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig-base",
|
||||
"extends": "../tsconfig-noncomposite-base",
|
||||
"compilerOptions": {
|
||||
"removeComments": true,
|
||||
"outFile": "../../built/local/watchGuard.js",
|
||||
@@ -13,4 +13,4 @@
|
||||
"files": [
|
||||
"watchGuard.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -14,7 +14,7 @@ and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace ts {
|
||||
const versionMajorMinor = "3.3";
|
||||
const versionMajorMinor = "3.4";
|
||||
/** The version of the TypeScript compiler release */
|
||||
const version: string;
|
||||
}
|
||||
@@ -815,7 +815,7 @@ declare namespace ts {
|
||||
}
|
||||
interface TypeOperatorNode extends TypeNode {
|
||||
kind: SyntaxKind.TypeOperator;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface IndexedAccessTypeNode extends TypeNode {
|
||||
@@ -2230,6 +2230,7 @@ declare namespace ts {
|
||||
}
|
||||
interface UniqueESSymbolType extends Type {
|
||||
symbol: Symbol;
|
||||
escapedName: __String;
|
||||
}
|
||||
interface StringLiteralType extends LiteralType {
|
||||
value: string;
|
||||
@@ -2298,6 +2299,7 @@ declare namespace ts {
|
||||
interface TupleType extends GenericType {
|
||||
minLength: number;
|
||||
hasRestElement: boolean;
|
||||
readonly: boolean;
|
||||
associatedNames?: __String[];
|
||||
}
|
||||
interface TupleTypeReference extends TypeReference {
|
||||
@@ -3776,7 +3778,7 @@ declare namespace ts {
|
||||
function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
|
||||
function createThisTypeNode(): ThisTypeNode;
|
||||
function createTypeOperatorNode(type: TypeNode): TypeOperatorNode;
|
||||
function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword, type: TypeNode): TypeOperatorNode;
|
||||
function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode;
|
||||
function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode;
|
||||
function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode;
|
||||
function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode;
|
||||
|
||||
+5
-3
@@ -14,7 +14,7 @@ and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
declare namespace ts {
|
||||
const versionMajorMinor = "3.3";
|
||||
const versionMajorMinor = "3.4";
|
||||
/** The version of the TypeScript compiler release */
|
||||
const version: string;
|
||||
}
|
||||
@@ -815,7 +815,7 @@ declare namespace ts {
|
||||
}
|
||||
interface TypeOperatorNode extends TypeNode {
|
||||
kind: SyntaxKind.TypeOperator;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword;
|
||||
operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword;
|
||||
type: TypeNode;
|
||||
}
|
||||
interface IndexedAccessTypeNode extends TypeNode {
|
||||
@@ -2230,6 +2230,7 @@ declare namespace ts {
|
||||
}
|
||||
interface UniqueESSymbolType extends Type {
|
||||
symbol: Symbol;
|
||||
escapedName: __String;
|
||||
}
|
||||
interface StringLiteralType extends LiteralType {
|
||||
value: string;
|
||||
@@ -2298,6 +2299,7 @@ declare namespace ts {
|
||||
interface TupleType extends GenericType {
|
||||
minLength: number;
|
||||
hasRestElement: boolean;
|
||||
readonly: boolean;
|
||||
associatedNames?: __String[];
|
||||
}
|
||||
interface TupleTypeReference extends TypeReference {
|
||||
@@ -3776,7 +3778,7 @@ declare namespace ts {
|
||||
function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
|
||||
function createThisTypeNode(): ThisTypeNode;
|
||||
function createTypeOperatorNode(type: TypeNode): TypeOperatorNode;
|
||||
function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword, type: TypeNode): TypeOperatorNode;
|
||||
function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode;
|
||||
function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode;
|
||||
function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode;
|
||||
function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode;
|
||||
|
||||
@@ -30,15 +30,15 @@ const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(is
|
||||
>isNumber : (x: any) => x is number
|
||||
|
||||
const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray<string | number | boolean>;
|
||||
>readonlyArrayOfStringsNumbersAndBooleans : ReadonlyArray<string | number | boolean>
|
||||
>arrayOfStringsNumbersAndBooleans as ReadonlyArray<string | number | boolean> : ReadonlyArray<string | number | boolean>
|
||||
>readonlyArrayOfStringsNumbersAndBooleans : readonly (string | number | boolean)[]
|
||||
>arrayOfStringsNumbersAndBooleans as ReadonlyArray<string | number | boolean> : readonly (string | number | boolean)[]
|
||||
>arrayOfStringsNumbersAndBooleans : (string | number | boolean)[]
|
||||
|
||||
const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber);
|
||||
>readonlyFoundNumber : number
|
||||
>readonlyArrayOfStringsNumbersAndBooleans.find(isNumber) : number
|
||||
>readonlyArrayOfStringsNumbersAndBooleans.find : { <S extends string | number | boolean>(predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray<string | number | boolean>) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray<string | number | boolean>) => boolean, thisArg?: any): string | number | boolean; }
|
||||
>readonlyArrayOfStringsNumbersAndBooleans : ReadonlyArray<string | number | boolean>
|
||||
>find : { <S extends string | number | boolean>(predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray<string | number | boolean>) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray<string | number | boolean>) => boolean, thisArg?: any): string | number | boolean; }
|
||||
>readonlyArrayOfStringsNumbersAndBooleans.find : { <S extends string | number | boolean>(predicate: (this: void, value: string | number | boolean, index: number, obj: readonly (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: readonly (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; }
|
||||
>readonlyArrayOfStringsNumbersAndBooleans : readonly (string | number | boolean)[]
|
||||
>find : { <S extends string | number | boolean>(predicate: (this: void, value: string | number | boolean, index: number, obj: readonly (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: readonly (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; }
|
||||
>isNumber : (x: any) => x is number
|
||||
|
||||
|
||||
@@ -4,22 +4,22 @@ const array: number[] = [];
|
||||
>[] : undefined[]
|
||||
|
||||
const readonlyArray: ReadonlyArray<number> = [];
|
||||
>readonlyArray : ReadonlyArray<number>
|
||||
>readonlyArray : readonly number[]
|
||||
>[] : undefined[]
|
||||
|
||||
array.flatMap((): ReadonlyArray<number> => []); // ok
|
||||
>array.flatMap((): ReadonlyArray<number> => []) : number[]
|
||||
>array.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | ReadonlyArray<U>, thisArg?: This) => U[]
|
||||
>array.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
|
||||
>array : number[]
|
||||
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | ReadonlyArray<U>, thisArg?: This) => U[]
|
||||
>(): ReadonlyArray<number> => [] : () => ReadonlyArray<number>
|
||||
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
|
||||
>(): ReadonlyArray<number> => [] : () => readonly number[]
|
||||
>[] : undefined[]
|
||||
|
||||
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
|
||||
>readonlyArray.flatMap((): ReadonlyArray<number> => []) : number[]
|
||||
>readonlyArray.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | ReadonlyArray<U>, thisArg?: This) => U[]
|
||||
>readonlyArray : ReadonlyArray<number>
|
||||
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | ReadonlyArray<U>, thisArg?: This) => U[]
|
||||
>(): ReadonlyArray<number> => [] : () => ReadonlyArray<number>
|
||||
>readonlyArray.flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
|
||||
>readonlyArray : readonly number[]
|
||||
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]
|
||||
>(): ReadonlyArray<number> => [] : () => readonly number[]
|
||||
>[] : undefined[]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
|
||||
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'readonly B[]'.
|
||||
Property 'b' is missing in type 'A' but required in type 'B'.
|
||||
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
|
||||
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
|
||||
Types of property 'concat' are incompatible.
|
||||
Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
|
||||
Type 'A[]' is not assignable to type 'B[]'.
|
||||
@@ -22,7 +22,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
|
||||
rra = arb;
|
||||
rrb = ara; // error: 'A' is not assignable to 'B'
|
||||
~~~
|
||||
!!! error TS2322: Type 'A[]' is not assignable to type 'ReadonlyArray<B>'.
|
||||
!!! error TS2322: Type 'A[]' is not assignable to type 'readonly B[]'.
|
||||
!!! error TS2322: Property 'b' is missing in type 'A' but required in type 'B'.
|
||||
!!! related TS2728 tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts:2:21: 'b' is declared here.
|
||||
|
||||
@@ -31,7 +31,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
|
||||
rrb = crb;
|
||||
rrb = cra; // error: 'A' is not assignable to 'B'
|
||||
~~~
|
||||
!!! error TS2322: Type 'C<A>' is not assignable to type 'ReadonlyArray<B>'.
|
||||
!!! error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
|
||||
!!! error TS2322: Types of property 'concat' are incompatible.
|
||||
!!! error TS2322: Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
|
||||
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
|
||||
|
||||
@@ -26,48 +26,48 @@ declare var crb: C<B>;
|
||||
>crb : C<B>
|
||||
|
||||
declare var rra: ReadonlyArray<A>;
|
||||
>rra : ReadonlyArray<A>
|
||||
>rra : readonly A[]
|
||||
|
||||
declare var rrb: ReadonlyArray<B>;
|
||||
>rrb : ReadonlyArray<B>
|
||||
>rrb : readonly B[]
|
||||
|
||||
rra = ara;
|
||||
>rra = ara : A[]
|
||||
>rra : ReadonlyArray<A>
|
||||
>rra : readonly A[]
|
||||
>ara : A[]
|
||||
|
||||
rrb = arb; // OK, Array<B> is assignable to ReadonlyArray<A>
|
||||
>rrb = arb : B[]
|
||||
>rrb : ReadonlyArray<B>
|
||||
>rrb : readonly B[]
|
||||
>arb : B[]
|
||||
|
||||
rra = arb;
|
||||
>rra = arb : B[]
|
||||
>rra : ReadonlyArray<A>
|
||||
>rra : readonly A[]
|
||||
>arb : B[]
|
||||
|
||||
rrb = ara; // error: 'A' is not assignable to 'B'
|
||||
>rrb = ara : A[]
|
||||
>rrb : ReadonlyArray<B>
|
||||
>rrb : readonly B[]
|
||||
>ara : A[]
|
||||
|
||||
rra = cra;
|
||||
>rra = cra : C<A>
|
||||
>rra : ReadonlyArray<A>
|
||||
>rra : readonly A[]
|
||||
>cra : C<A>
|
||||
|
||||
rra = crb; // OK, C<B> is assignable to ReadonlyArray<A>
|
||||
>rra = crb : C<B>
|
||||
>rra : ReadonlyArray<A>
|
||||
>rra : readonly A[]
|
||||
>crb : C<B>
|
||||
|
||||
rrb = crb;
|
||||
>rrb = crb : C<B>
|
||||
>rrb : ReadonlyArray<B>
|
||||
>rrb : readonly B[]
|
||||
>crb : C<B>
|
||||
|
||||
rrb = cra; // error: 'A' is not assignable to 'B'
|
||||
>rrb = cra : C<A>
|
||||
>rrb : ReadonlyArray<B>
|
||||
>rrb : readonly B[]
|
||||
>cra : C<A>
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
interface Array<T> {
|
||||
equalsShallow<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>): boolean;
|
||||
>equalsShallow : <T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean
|
||||
>this : ReadonlyArray<T>
|
||||
>other : ReadonlyArray<T>
|
||||
>equalsShallow : <T>(this: readonly T[], other: readonly T[]) => boolean
|
||||
>this : readonly T[]
|
||||
>other : readonly T[]
|
||||
}
|
||||
|
||||
declare const a: (string | number)[] | null[] | undefined[] | {}[];
|
||||
@@ -19,8 +19,8 @@ declare const b: (string | number)[] | null[] | undefined[] | {}[];
|
||||
let x = a.equalsShallow(b);
|
||||
>x : boolean
|
||||
>a.equalsShallow(b) : boolean
|
||||
>a.equalsShallow : (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean)
|
||||
>a.equalsShallow : (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean)
|
||||
>a : (string | number)[] | null[] | undefined[] | {}[]
|
||||
>equalsShallow : (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean) | (<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>) => boolean)
|
||||
>equalsShallow : (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean)
|
||||
>b : (string | number)[] | null[] | undefined[] | {}[]
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
Object.freeze({
|
||||
>Object.freeze({ foo() { return Object.freeze('a'); },}) : Readonly<{ foo(): string; }>
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>{ foo() { return Object.freeze('a'); },} : { foo(): string; }
|
||||
|
||||
foo() {
|
||||
@@ -13,9 +13,9 @@ Object.freeze({
|
||||
|
||||
return Object.freeze('a');
|
||||
>Object.freeze('a') : string
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>'a' : "a"
|
||||
|
||||
},
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
tests/cases/compiler/crashInGetTextOfComputedPropertyName.ts(23,24): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
|
||||
|
||||
==== tests/cases/compiler/crashInGetTextOfComputedPropertyName.ts (1 errors) ====
|
||||
// https://github.com/Microsoft/TypeScript/issues/29006
|
||||
export interface A { type: 'a' }
|
||||
export interface B { type: 'b' }
|
||||
export type AB = A | B
|
||||
|
||||
const itemId = 'some-id'
|
||||
|
||||
// --- test on first level ---
|
||||
const items: { [id: string]: AB } = {}
|
||||
const { [itemId]: itemOk1 } = items
|
||||
typeof itemOk1 // pass
|
||||
|
||||
// --- test on second level ---
|
||||
interface ObjWithItems {
|
||||
items: {[s: string]: AB}
|
||||
}
|
||||
const objWithItems: ObjWithItems = { items: {}}
|
||||
|
||||
const itemOk2 = objWithItems.items[itemId]
|
||||
typeof itemOk2 // pass
|
||||
|
||||
const {
|
||||
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
} = objWithItems
|
||||
|
||||
// in order to re-produce the error, uncomment next line:
|
||||
typeof itemWithTSError // :(
|
||||
|
||||
// will result in:
|
||||
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|
||||
@@ -0,0 +1,48 @@
|
||||
//// [crashInGetTextOfComputedPropertyName.ts]
|
||||
// https://github.com/Microsoft/TypeScript/issues/29006
|
||||
export interface A { type: 'a' }
|
||||
export interface B { type: 'b' }
|
||||
export type AB = A | B
|
||||
|
||||
const itemId = 'some-id'
|
||||
|
||||
// --- test on first level ---
|
||||
const items: { [id: string]: AB } = {}
|
||||
const { [itemId]: itemOk1 } = items
|
||||
typeof itemOk1 // pass
|
||||
|
||||
// --- test on second level ---
|
||||
interface ObjWithItems {
|
||||
items: {[s: string]: AB}
|
||||
}
|
||||
const objWithItems: ObjWithItems = { items: {}}
|
||||
|
||||
const itemOk2 = objWithItems.items[itemId]
|
||||
typeof itemOk2 // pass
|
||||
|
||||
const {
|
||||
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
|
||||
} = objWithItems
|
||||
|
||||
// in order to re-produce the error, uncomment next line:
|
||||
typeof itemWithTSError // :(
|
||||
|
||||
// will result in:
|
||||
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|
||||
|
||||
//// [crashInGetTextOfComputedPropertyName.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var itemId = 'some-id';
|
||||
// --- test on first level ---
|
||||
var items = {};
|
||||
var _a = itemId, itemOk1 = items[_a];
|
||||
typeof itemOk1; // pass
|
||||
var objWithItems = { items: {} };
|
||||
var itemOk2 = objWithItems.items[itemId];
|
||||
typeof itemOk2; // pass
|
||||
var _b = objWithItems.items /*happens when default value is provided*/, _c = itemId, itemWithTSError = (_b === void 0 ? {} /*happens when default value is provided*/ : _b)[_c];
|
||||
// in order to re-produce the error, uncomment next line:
|
||||
typeof itemWithTSError; // :(
|
||||
// will result in:
|
||||
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/compiler/crashInGetTextOfComputedPropertyName.ts ===
|
||||
// https://github.com/Microsoft/TypeScript/issues/29006
|
||||
export interface A { type: 'a' }
|
||||
>A : Symbol(A, Decl(crashInGetTextOfComputedPropertyName.ts, 0, 0))
|
||||
>type : Symbol(A.type, Decl(crashInGetTextOfComputedPropertyName.ts, 1, 20))
|
||||
|
||||
export interface B { type: 'b' }
|
||||
>B : Symbol(B, Decl(crashInGetTextOfComputedPropertyName.ts, 1, 32))
|
||||
>type : Symbol(B.type, Decl(crashInGetTextOfComputedPropertyName.ts, 2, 20))
|
||||
|
||||
export type AB = A | B
|
||||
>AB : Symbol(AB, Decl(crashInGetTextOfComputedPropertyName.ts, 2, 32))
|
||||
>A : Symbol(A, Decl(crashInGetTextOfComputedPropertyName.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(crashInGetTextOfComputedPropertyName.ts, 1, 32))
|
||||
|
||||
const itemId = 'some-id'
|
||||
>itemId : Symbol(itemId, Decl(crashInGetTextOfComputedPropertyName.ts, 5, 5))
|
||||
|
||||
// --- test on first level ---
|
||||
const items: { [id: string]: AB } = {}
|
||||
>items : Symbol(items, Decl(crashInGetTextOfComputedPropertyName.ts, 8, 5))
|
||||
>id : Symbol(id, Decl(crashInGetTextOfComputedPropertyName.ts, 8, 16))
|
||||
>AB : Symbol(AB, Decl(crashInGetTextOfComputedPropertyName.ts, 2, 32))
|
||||
|
||||
const { [itemId]: itemOk1 } = items
|
||||
>itemId : Symbol(itemId, Decl(crashInGetTextOfComputedPropertyName.ts, 5, 5))
|
||||
>itemOk1 : Symbol(itemOk1, Decl(crashInGetTextOfComputedPropertyName.ts, 9, 7))
|
||||
>items : Symbol(items, Decl(crashInGetTextOfComputedPropertyName.ts, 8, 5))
|
||||
|
||||
typeof itemOk1 // pass
|
||||
>itemOk1 : Symbol(itemOk1, Decl(crashInGetTextOfComputedPropertyName.ts, 9, 7))
|
||||
|
||||
// --- test on second level ---
|
||||
interface ObjWithItems {
|
||||
>ObjWithItems : Symbol(ObjWithItems, Decl(crashInGetTextOfComputedPropertyName.ts, 10, 14))
|
||||
|
||||
items: {[s: string]: AB}
|
||||
>items : Symbol(ObjWithItems.items, Decl(crashInGetTextOfComputedPropertyName.ts, 13, 24))
|
||||
>s : Symbol(s, Decl(crashInGetTextOfComputedPropertyName.ts, 14, 13))
|
||||
>AB : Symbol(AB, Decl(crashInGetTextOfComputedPropertyName.ts, 2, 32))
|
||||
}
|
||||
const objWithItems: ObjWithItems = { items: {}}
|
||||
>objWithItems : Symbol(objWithItems, Decl(crashInGetTextOfComputedPropertyName.ts, 16, 5))
|
||||
>ObjWithItems : Symbol(ObjWithItems, Decl(crashInGetTextOfComputedPropertyName.ts, 10, 14))
|
||||
>items : Symbol(items, Decl(crashInGetTextOfComputedPropertyName.ts, 16, 36))
|
||||
|
||||
const itemOk2 = objWithItems.items[itemId]
|
||||
>itemOk2 : Symbol(itemOk2, Decl(crashInGetTextOfComputedPropertyName.ts, 18, 5))
|
||||
>objWithItems.items : Symbol(ObjWithItems.items, Decl(crashInGetTextOfComputedPropertyName.ts, 13, 24))
|
||||
>objWithItems : Symbol(objWithItems, Decl(crashInGetTextOfComputedPropertyName.ts, 16, 5))
|
||||
>items : Symbol(ObjWithItems.items, Decl(crashInGetTextOfComputedPropertyName.ts, 13, 24))
|
||||
>itemId : Symbol(itemId, Decl(crashInGetTextOfComputedPropertyName.ts, 5, 5))
|
||||
|
||||
typeof itemOk2 // pass
|
||||
>itemOk2 : Symbol(itemOk2, Decl(crashInGetTextOfComputedPropertyName.ts, 18, 5))
|
||||
|
||||
const {
|
||||
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
|
||||
>items : Symbol(ObjWithItems.items, Decl(crashInGetTextOfComputedPropertyName.ts, 13, 24))
|
||||
>itemId : Symbol(itemId, Decl(crashInGetTextOfComputedPropertyName.ts, 5, 5))
|
||||
>itemWithTSError : Symbol(itemWithTSError, Decl(crashInGetTextOfComputedPropertyName.ts, 22, 12))
|
||||
|
||||
} = objWithItems
|
||||
>objWithItems : Symbol(objWithItems, Decl(crashInGetTextOfComputedPropertyName.ts, 16, 5))
|
||||
|
||||
// in order to re-produce the error, uncomment next line:
|
||||
typeof itemWithTSError // :(
|
||||
>itemWithTSError : Symbol(itemWithTSError, Decl(crashInGetTextOfComputedPropertyName.ts, 22, 12))
|
||||
|
||||
// will result in:
|
||||
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/compiler/crashInGetTextOfComputedPropertyName.ts ===
|
||||
// https://github.com/Microsoft/TypeScript/issues/29006
|
||||
export interface A { type: 'a' }
|
||||
>type : "a"
|
||||
|
||||
export interface B { type: 'b' }
|
||||
>type : "b"
|
||||
|
||||
export type AB = A | B
|
||||
>AB : AB
|
||||
|
||||
const itemId = 'some-id'
|
||||
>itemId : "some-id"
|
||||
>'some-id' : "some-id"
|
||||
|
||||
// --- test on first level ---
|
||||
const items: { [id: string]: AB } = {}
|
||||
>items : { [id: string]: AB; }
|
||||
>id : string
|
||||
>{} : {}
|
||||
|
||||
const { [itemId]: itemOk1 } = items
|
||||
>itemId : "some-id"
|
||||
>itemOk1 : AB
|
||||
>items : { [id: string]: AB; }
|
||||
|
||||
typeof itemOk1 // pass
|
||||
>typeof itemOk1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>itemOk1 : AB
|
||||
|
||||
// --- test on second level ---
|
||||
interface ObjWithItems {
|
||||
items: {[s: string]: AB}
|
||||
>items : { [s: string]: AB; }
|
||||
>s : string
|
||||
}
|
||||
const objWithItems: ObjWithItems = { items: {}}
|
||||
>objWithItems : ObjWithItems
|
||||
>{ items: {}} : { items: {}; }
|
||||
>items : {}
|
||||
>{} : {}
|
||||
|
||||
const itemOk2 = objWithItems.items[itemId]
|
||||
>itemOk2 : AB
|
||||
>objWithItems.items[itemId] : AB
|
||||
>objWithItems.items : { [s: string]: AB; }
|
||||
>objWithItems : ObjWithItems
|
||||
>items : { [s: string]: AB; }
|
||||
>itemId : "some-id"
|
||||
|
||||
typeof itemOk2 // pass
|
||||
>typeof itemOk2 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>itemOk2 : AB
|
||||
|
||||
const {
|
||||
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
|
||||
>items : any
|
||||
>itemId : "some-id"
|
||||
>itemWithTSError : any
|
||||
>{} : { some-id: any; }
|
||||
|
||||
} = objWithItems
|
||||
>objWithItems : ObjWithItems
|
||||
|
||||
// in order to re-produce the error, uncomment next line:
|
||||
typeof itemWithTSError // :(
|
||||
>typeof itemWithTSError : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>itemWithTSError : any
|
||||
|
||||
// will result in:
|
||||
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|
||||
@@ -1,9 +1,10 @@
|
||||
tests/cases/compiler/destructureComputedProperty.ts(7,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructureComputedProperty.ts(8,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructureComputedProperty.ts(9,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/destructureComputedProperty.ts (3 errors) ====
|
||||
==== tests/cases/compiler/destructureComputedProperty.ts (4 errors) ====
|
||||
declare const ab: { n: number } | { n: string };
|
||||
const nameN = "n";
|
||||
const { [nameN]: n } = ab;
|
||||
@@ -17,6 +18,8 @@ tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Propert
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
const { [nameP]: p2 } = new C();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
const { p: p3 } = new C();
|
||||
~~~~~~~~~
|
||||
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,8): error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
|
||||
tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,21): error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,37): error TS2353: Object literal may only specify known properties, and 'prop' does not exist in type '{ prop2: any; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts (1 errors) ====
|
||||
==== tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts (2 errors) ====
|
||||
let { [Symbol.iterator]: destructured } = [];
|
||||
void destructured;
|
||||
|
||||
@@ -13,6 +14,8 @@ tests/cases/compiler/destructuredLateBoundNameHasCorrectTypes.ts(11,8): error TS
|
||||
const notPresent = "prop2";
|
||||
|
||||
let { [notPresent]: computed2 } = { prop: "b" };
|
||||
~~~~~~~~~~
|
||||
!!! error TS2339: Property 'prop2' does not exist on type '{ prop: string; }'.
|
||||
~~~~~~~~~
|
||||
!!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value.
|
||||
~~~~
|
||||
!!! error TS2353: Object literal may only specify known properties, and 'prop' does not exist in type '{ prop2: any; }'.
|
||||
|
||||
@@ -32,7 +32,7 @@ const notPresent = "prop2";
|
||||
let { [notPresent]: computed2 } = { prop: "b" };
|
||||
>notPresent : "prop2"
|
||||
>computed2 : any
|
||||
>{ prop: "b" } : { prop: string; }
|
||||
>{ prop: "b" } : { prop: string; prop2: any; }
|
||||
>prop : string
|
||||
>"b" : "b"
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
tests/cases/compiler/destructuringAssignment_private.ts(6,10): error TS2341: Property 'x' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructuringAssignment_private.ts(7,4): error TS2341: Property 'o' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructuringAssignment_private.ts(10,10): error TS2341: Property 'x' is private and only accessible within class 'C'.
|
||||
tests/cases/compiler/destructuringAssignment_private.ts(13,4): error TS2341: Property 'o' is private and only accessible within class 'C'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/destructuringAssignment_private.ts (2 errors) ====
|
||||
==== tests/cases/compiler/destructuringAssignment_private.ts (4 errors) ====
|
||||
class C {
|
||||
private x = 0;
|
||||
private o = [{ a: 1 }];
|
||||
@@ -14,4 +16,14 @@ tests/cases/compiler/destructuringAssignment_private.ts(7,4): error TS2341: Prop
|
||||
({ o: [{ a: x }]} = new C());
|
||||
~
|
||||
!!! error TS2341: Property 'o' is private and only accessible within class 'C'.
|
||||
|
||||
const nameX = "x";
|
||||
([{ a: { [nameX]: x } }] = [{ a: new C() }]);
|
||||
~~~~~~~
|
||||
!!! error TS2341: Property 'x' is private and only accessible within class 'C'.
|
||||
|
||||
const nameO = "o";
|
||||
({ [nameO]: [{ a: x }]} = new C());
|
||||
~~~~~~~
|
||||
!!! error TS2341: Property 'o' is private and only accessible within class 'C'.
|
||||
|
||||
@@ -6,9 +6,16 @@ class C {
|
||||
let x: number;
|
||||
([{ a: { x } }] = [{ a: new C() }]);
|
||||
({ o: [{ a: x }]} = new C());
|
||||
|
||||
const nameX = "x";
|
||||
([{ a: { [nameX]: x } }] = [{ a: new C() }]);
|
||||
|
||||
const nameO = "o";
|
||||
({ [nameO]: [{ a: x }]} = new C());
|
||||
|
||||
|
||||
//// [destructuringAssignment_private.js]
|
||||
var _a, _b;
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
this.x = 0;
|
||||
@@ -19,3 +26,7 @@ var C = /** @class */ (function () {
|
||||
var x;
|
||||
(x = [{ a: new C() }][0].a.x);
|
||||
(x = new C().o[0].a);
|
||||
var nameX = "x";
|
||||
(_a = nameX, x = [{ a: new C() }][0].a[_a]);
|
||||
var nameO = "o";
|
||||
(_b = nameO, x = new C()[_b][0].a);
|
||||
|
||||
@@ -24,3 +24,24 @@ let x: number;
|
||||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 4, 3))
|
||||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0))
|
||||
|
||||
const nameX = "x";
|
||||
>nameX : Symbol(nameX, Decl(destructuringAssignment_private.ts, 8, 5))
|
||||
|
||||
([{ a: { [nameX]: x } }] = [{ a: new C() }]);
|
||||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 9, 3))
|
||||
>[nameX] : Symbol([nameX], Decl(destructuringAssignment_private.ts, 9, 8))
|
||||
>nameX : Symbol(nameX, Decl(destructuringAssignment_private.ts, 8, 5))
|
||||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 4, 3))
|
||||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 9, 29))
|
||||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0))
|
||||
|
||||
const nameO = "o";
|
||||
>nameO : Symbol(nameO, Decl(destructuringAssignment_private.ts, 11, 5))
|
||||
|
||||
({ [nameO]: [{ a: x }]} = new C());
|
||||
>[nameO] : Symbol([nameO], Decl(destructuringAssignment_private.ts, 12, 2))
|
||||
>nameO : Symbol(nameO, Decl(destructuringAssignment_private.ts, 11, 5))
|
||||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 12, 14))
|
||||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 4, 3))
|
||||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0))
|
||||
|
||||
|
||||
@@ -42,3 +42,40 @@ let x: number;
|
||||
>new C() : C
|
||||
>C : typeof C
|
||||
|
||||
const nameX = "x";
|
||||
>nameX : "x"
|
||||
>"x" : "x"
|
||||
|
||||
([{ a: { [nameX]: x } }] = [{ a: new C() }]);
|
||||
>([{ a: { [nameX]: x } }] = [{ a: new C() }]) : [{ a: C; }]
|
||||
>[{ a: { [nameX]: x } }] = [{ a: new C() }] : [{ a: C; }]
|
||||
>[{ a: { [nameX]: x } }] : [{ a: { [nameX]: number; }; }]
|
||||
>{ a: { [nameX]: x } } : { a: { [nameX]: number; }; }
|
||||
>a : { [nameX]: number; }
|
||||
>{ [nameX]: x } : { [nameX]: number; }
|
||||
>[nameX] : number
|
||||
>nameX : "x"
|
||||
>x : number
|
||||
>[{ a: new C() }] : [{ a: C; }]
|
||||
>{ a: new C() } : { a: C; }
|
||||
>a : C
|
||||
>new C() : C
|
||||
>C : typeof C
|
||||
|
||||
const nameO = "o";
|
||||
>nameO : "o"
|
||||
>"o" : "o"
|
||||
|
||||
({ [nameO]: [{ a: x }]} = new C());
|
||||
>({ [nameO]: [{ a: x }]} = new C()) : C
|
||||
>{ [nameO]: [{ a: x }]} = new C() : C
|
||||
>{ [nameO]: [{ a: x }]} : { [nameO]: [{ a: number; }]; }
|
||||
>[nameO] : [{ a: number; }]
|
||||
>nameO : "o"
|
||||
>[{ a: x }] : [{ a: number; }]
|
||||
>{ a: x } : { a: number; }
|
||||
>a : number
|
||||
>x : number
|
||||
>new C() : C
|
||||
>C : typeof C
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
=== tests/cases/compiler/doNotInferUnrelatedTypes.ts ===
|
||||
// #16709
|
||||
declare function dearray<T>(ara: ReadonlyArray<T>): T;
|
||||
>dearray : <T>(ara: ReadonlyArray<T>) => T
|
||||
>ara : ReadonlyArray<T>
|
||||
>dearray : <T>(ara: readonly T[]) => T
|
||||
>ara : readonly T[]
|
||||
|
||||
type LiteralType = "foo" | "bar";
|
||||
>LiteralType : LiteralType
|
||||
@@ -13,6 +13,6 @@ declare var alt: Array<LiteralType>;
|
||||
let foo: LiteralType = dearray(alt);
|
||||
>foo : LiteralType
|
||||
>dearray(alt) : LiteralType
|
||||
>dearray : <T>(ara: ReadonlyArray<T>) => T
|
||||
>dearray : <T>(ara: readonly T[]) => T
|
||||
>alt : LiteralType[]
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
tests/cases/compiler/infiniteConstraints.ts(3,37): error TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||
tests/cases/compiler/infiniteConstraints.ts(4,37): error TS2536: Type '"val"' cannot be used to index type 'B[Exclude<keyof B, K>]'.
|
||||
tests/cases/compiler/infiniteConstraints.ts(31,43): error TS2322: Type 'Record<"val", "dup">' is not assignable to type 'never'.
|
||||
tests/cases/compiler/infiniteConstraints.ts(31,63): error TS2322: Type 'Record<"val", "dup">' is not assignable to type 'never'.
|
||||
tests/cases/compiler/infiniteConstraints.ts(36,71): error TS2536: Type '"foo"' cannot be used to index type 'T[keyof T]'.
|
||||
tests/cases/compiler/infiniteConstraints.ts(36,71): error TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||
|
||||
|
||||
==== tests/cases/compiler/infiniteConstraints.ts (4 errors) ====
|
||||
==== tests/cases/compiler/infiniteConstraints.ts (6 errors) ====
|
||||
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
|
||||
|
||||
type T1<B extends { [K in keyof B]: Extract<B[Exclude<keyof B, K>], { val: string }>["val"] }> = B;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||
type T2<B extends { [K in keyof B]: B[Exclude<keyof B, K>]["val"] }> = B;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2536: Type '"val"' cannot be used to index type 'B[Exclude<keyof B, K>]'.
|
||||
@@ -51,4 +55,6 @@ tests/cases/compiler/infiniteConstraints.ts(36,71): error TS2536: Type '"foo"' c
|
||||
declare function function1<T extends {[K in keyof T]: Cond<T[K]>}>(): T[keyof T]["foo"];
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2536: Type '"foo"' cannot be used to index type 'T[keyof T]'.
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||
|
||||
@@ -43,7 +43,7 @@ declare function from<T>(): T[];
|
||||
>from : <T>() => T[]
|
||||
|
||||
const c2: ReadonlyArray<A> = from();
|
||||
>c2 : ReadonlyArray<Nominal<"A", string>>
|
||||
>c2 : readonly Nominal<"A", string>[]
|
||||
>from() : Nominal<"A", string>[]
|
||||
>from : <T>() => T[]
|
||||
|
||||
|
||||
@@ -1873,9 +1873,9 @@ class SampleClass<P> {
|
||||
>this : this
|
||||
>props : Readonly<P>
|
||||
>Object.freeze(props) : Readonly<P>
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>props : P
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//// [mappedToToIndexSignatureInference.ts]
|
||||
declare const fn: <K extends string, V>(object: { [Key in K]: V }) => object;
|
||||
declare const a: { [index: string]: number };
|
||||
fn(a);
|
||||
|
||||
|
||||
//// [mappedToToIndexSignatureInference.js]
|
||||
fn(a);
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/compiler/mappedToToIndexSignatureInference.ts ===
|
||||
declare const fn: <K extends string, V>(object: { [Key in K]: V }) => object;
|
||||
>fn : Symbol(fn, Decl(mappedToToIndexSignatureInference.ts, 0, 13))
|
||||
>K : Symbol(K, Decl(mappedToToIndexSignatureInference.ts, 0, 19))
|
||||
>V : Symbol(V, Decl(mappedToToIndexSignatureInference.ts, 0, 36))
|
||||
>object : Symbol(object, Decl(mappedToToIndexSignatureInference.ts, 0, 40))
|
||||
>Key : Symbol(Key, Decl(mappedToToIndexSignatureInference.ts, 0, 51))
|
||||
>K : Symbol(K, Decl(mappedToToIndexSignatureInference.ts, 0, 19))
|
||||
>V : Symbol(V, Decl(mappedToToIndexSignatureInference.ts, 0, 36))
|
||||
|
||||
declare const a: { [index: string]: number };
|
||||
>a : Symbol(a, Decl(mappedToToIndexSignatureInference.ts, 1, 13))
|
||||
>index : Symbol(index, Decl(mappedToToIndexSignatureInference.ts, 1, 20))
|
||||
|
||||
fn(a);
|
||||
>fn : Symbol(fn, Decl(mappedToToIndexSignatureInference.ts, 0, 13))
|
||||
>a : Symbol(a, Decl(mappedToToIndexSignatureInference.ts, 1, 13))
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/mappedToToIndexSignatureInference.ts ===
|
||||
declare const fn: <K extends string, V>(object: { [Key in K]: V }) => object;
|
||||
>fn : <K extends string, V>(object: { [Key in K]: V; }) => object
|
||||
>object : { [Key in K]: V; }
|
||||
|
||||
declare const a: { [index: string]: number };
|
||||
>a : { [index: string]: number; }
|
||||
>index : string
|
||||
|
||||
fn(a);
|
||||
>fn(a) : object
|
||||
>fn : <K extends string, V>(object: { [Key in K]: V; }) => object
|
||||
>a : { [index: string]: number; }
|
||||
|
||||
@@ -28,6 +28,14 @@ type B = { b: string };
|
||||
|
||||
type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>;
|
||||
|
||||
type ReadWrite<T> = { -readonly [P in keyof T] : T[P] };
|
||||
|
||||
type T50 = Readonly<string[]>;
|
||||
type T51 = Readonly<[number, number]>;
|
||||
type T52 = Partial<Readonly<string[]>>;
|
||||
type T53 = Readonly<Partial<string[]>>;
|
||||
type T54 = ReadWrite<Required<T53>>;
|
||||
|
||||
declare function unboxify<T>(x: Boxified<T>): T;
|
||||
|
||||
declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]];
|
||||
@@ -147,6 +155,14 @@ declare type B = {
|
||||
b: string;
|
||||
};
|
||||
declare type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>;
|
||||
declare type ReadWrite<T> = {
|
||||
-readonly [P in keyof T]: T[P];
|
||||
};
|
||||
declare type T50 = Readonly<string[]>;
|
||||
declare type T51 = Readonly<[number, number]>;
|
||||
declare type T52 = Partial<Readonly<string[]>>;
|
||||
declare type T53 = Readonly<Partial<string[]>>;
|
||||
declare type T54 = ReadWrite<Required<T53>>;
|
||||
declare function unboxify<T>(x: Boxified<T>): T;
|
||||
declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]];
|
||||
declare let y10: [number, string, ...boolean[]];
|
||||
|
||||
@@ -108,247 +108,279 @@ type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>;
|
||||
>A : Symbol(A, Decl(mappedTypesArraysTuples.ts, 22, 39))
|
||||
>B : Symbol(B, Decl(mappedTypesArraysTuples.ts, 24, 23))
|
||||
|
||||
type ReadWrite<T> = { -readonly [P in keyof T] : T[P] };
|
||||
>ReadWrite : Symbol(ReadWrite, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 15))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 29, 33))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 15))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 15))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 29, 33))
|
||||
|
||||
type T50 = Readonly<string[]>;
|
||||
>T50 : Symbol(T50, Decl(mappedTypesArraysTuples.ts, 29, 56))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T51 = Readonly<[number, number]>;
|
||||
>T51 : Symbol(T51, Decl(mappedTypesArraysTuples.ts, 31, 30))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T52 = Partial<Readonly<string[]>>;
|
||||
>T52 : Symbol(T52, Decl(mappedTypesArraysTuples.ts, 32, 38))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T53 = Readonly<Partial<string[]>>;
|
||||
>T53 : Symbol(T53, Decl(mappedTypesArraysTuples.ts, 33, 39))
|
||||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T54 = ReadWrite<Required<T53>>;
|
||||
>T54 : Symbol(T54, Decl(mappedTypesArraysTuples.ts, 34, 39))
|
||||
>ReadWrite : Symbol(ReadWrite, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))
|
||||
>T53 : Symbol(T53, Decl(mappedTypesArraysTuples.ts, 33, 39))
|
||||
|
||||
declare function unboxify<T>(x: Boxified<T>): T;
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 26))
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 29, 29))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 35, 36))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 37, 26))
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 37, 29))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypesArraysTuples.ts, 0, 27))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 29, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 37, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 37, 26))
|
||||
|
||||
declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]];
|
||||
>x10 : Symbol(x10, Decl(mappedTypesArraysTuples.ts, 31, 11))
|
||||
>x10 : Symbol(x10, Decl(mappedTypesArraysTuples.ts, 39, 11))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
|
||||
let y10 = unboxify(x10);
|
||||
>y10 : Symbol(y10, Decl(mappedTypesArraysTuples.ts, 32, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>x10 : Symbol(x10, Decl(mappedTypesArraysTuples.ts, 31, 11))
|
||||
>y10 : Symbol(y10, Decl(mappedTypesArraysTuples.ts, 40, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 35, 36))
|
||||
>x10 : Symbol(x10, Decl(mappedTypesArraysTuples.ts, 39, 11))
|
||||
|
||||
declare let x11: Box<number>[];
|
||||
>x11 : Symbol(x11, Decl(mappedTypesArraysTuples.ts, 34, 11))
|
||||
>x11 : Symbol(x11, Decl(mappedTypesArraysTuples.ts, 42, 11))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
|
||||
let y11 = unboxify(x11);
|
||||
>y11 : Symbol(y11, Decl(mappedTypesArraysTuples.ts, 35, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>x11 : Symbol(x11, Decl(mappedTypesArraysTuples.ts, 34, 11))
|
||||
>y11 : Symbol(y11, Decl(mappedTypesArraysTuples.ts, 43, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 35, 36))
|
||||
>x11 : Symbol(x11, Decl(mappedTypesArraysTuples.ts, 42, 11))
|
||||
|
||||
declare let x12: { a: Box<number>, b: Box<string[]> };
|
||||
>x12 : Symbol(x12, Decl(mappedTypesArraysTuples.ts, 37, 11))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 37, 18))
|
||||
>x12 : Symbol(x12, Decl(mappedTypesArraysTuples.ts, 45, 11))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 45, 18))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 37, 34))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 45, 34))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
|
||||
let y12 = unboxify(x12);
|
||||
>y12 : Symbol(y12, Decl(mappedTypesArraysTuples.ts, 38, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 27, 77))
|
||||
>x12 : Symbol(x12, Decl(mappedTypesArraysTuples.ts, 37, 11))
|
||||
>y12 : Symbol(y12, Decl(mappedTypesArraysTuples.ts, 46, 3))
|
||||
>unboxify : Symbol(unboxify, Decl(mappedTypesArraysTuples.ts, 35, 36))
|
||||
>x12 : Symbol(x12, Decl(mappedTypesArraysTuples.ts, 45, 11))
|
||||
|
||||
declare function nonpartial<T>(x: Partial<T>): T;
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 38, 24))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 40, 28))
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 40, 31))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 48, 28))
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 48, 31))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 40, 28))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 40, 28))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 48, 28))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 48, 28))
|
||||
|
||||
declare let x20: [number | undefined, string?, ...boolean[]];
|
||||
>x20 : Symbol(x20, Decl(mappedTypesArraysTuples.ts, 42, 11))
|
||||
>x20 : Symbol(x20, Decl(mappedTypesArraysTuples.ts, 50, 11))
|
||||
|
||||
let y20 = nonpartial(x20);
|
||||
>y20 : Symbol(y20, Decl(mappedTypesArraysTuples.ts, 43, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 38, 24))
|
||||
>x20 : Symbol(x20, Decl(mappedTypesArraysTuples.ts, 42, 11))
|
||||
>y20 : Symbol(y20, Decl(mappedTypesArraysTuples.ts, 51, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24))
|
||||
>x20 : Symbol(x20, Decl(mappedTypesArraysTuples.ts, 50, 11))
|
||||
|
||||
declare let x21: (number | undefined)[];
|
||||
>x21 : Symbol(x21, Decl(mappedTypesArraysTuples.ts, 45, 11))
|
||||
>x21 : Symbol(x21, Decl(mappedTypesArraysTuples.ts, 53, 11))
|
||||
|
||||
let y21 = nonpartial(x21);
|
||||
>y21 : Symbol(y21, Decl(mappedTypesArraysTuples.ts, 46, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 38, 24))
|
||||
>x21 : Symbol(x21, Decl(mappedTypesArraysTuples.ts, 45, 11))
|
||||
>y21 : Symbol(y21, Decl(mappedTypesArraysTuples.ts, 54, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24))
|
||||
>x21 : Symbol(x21, Decl(mappedTypesArraysTuples.ts, 53, 11))
|
||||
|
||||
declare let x22: { a: number | undefined, b?: string[] };
|
||||
>x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 48, 11))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 48, 18))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 48, 41))
|
||||
>x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 56, 11))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 18))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 56, 41))
|
||||
|
||||
let y22 = nonpartial(x22);
|
||||
>y22 : Symbol(y22, Decl(mappedTypesArraysTuples.ts, 49, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 38, 24))
|
||||
>x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 48, 11))
|
||||
>y22 : Symbol(y22, Decl(mappedTypesArraysTuples.ts, 57, 3))
|
||||
>nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24))
|
||||
>x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 56, 11))
|
||||
|
||||
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
||||
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 49, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 51, 13))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 51, 13))
|
||||
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
|
||||
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 51, 45))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 51, 45))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 51, 13))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13))
|
||||
|
||||
type Awaitified<T> = { [P in keyof T]: Awaited<T[P]> };
|
||||
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 51, 57))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 52, 16))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 52, 24))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 52, 16))
|
||||
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 49, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 52, 16))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 52, 24))
|
||||
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
|
||||
>Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16))
|
||||
>P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24))
|
||||
|
||||
declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>;
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 52, 55))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 54, 21))
|
||||
>values : Symbol(values, Decl(mappedTypesArraysTuples.ts, 54, 38))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 54, 21))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
|
||||
>values : Symbol(values, Decl(mappedTypesArraysTuples.ts, 62, 38))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
|
||||
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 51, 57))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 54, 21))
|
||||
>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21))
|
||||
|
||||
function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>) {
|
||||
>f1 : Symbol(f1, Decl(mappedTypesArraysTuples.ts, 54, 76))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 56, 22))
|
||||
>f1 : Symbol(f1, Decl(mappedTypesArraysTuples.ts, 62, 76))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 56, 42))
|
||||
>d : Symbol(d, Decl(mappedTypesArraysTuples.ts, 56, 55))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42))
|
||||
>d : Symbol(d, Decl(mappedTypesArraysTuples.ts, 64, 55))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
let x1 = all(a);
|
||||
>x1 : Symbol(x1, Decl(mappedTypesArraysTuples.ts, 57, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 52, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 12))
|
||||
>x1 : Symbol(x1, Decl(mappedTypesArraysTuples.ts, 65, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
|
||||
|
||||
let x2 = all(a, b);
|
||||
>x2 : Symbol(x2, Decl(mappedTypesArraysTuples.ts, 58, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 52, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 56, 22))
|
||||
>x2 : Symbol(x2, Decl(mappedTypesArraysTuples.ts, 66, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
|
||||
|
||||
let x3 = all(a, b, c);
|
||||
>x3 : Symbol(x3, Decl(mappedTypesArraysTuples.ts, 59, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 52, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 56, 22))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 56, 42))
|
||||
>x3 : Symbol(x3, Decl(mappedTypesArraysTuples.ts, 67, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42))
|
||||
|
||||
let x4 = all(a, b, c, d);
|
||||
>x4 : Symbol(x4, Decl(mappedTypesArraysTuples.ts, 60, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 52, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 56, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 56, 22))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 56, 42))
|
||||
>d : Symbol(d, Decl(mappedTypesArraysTuples.ts, 56, 55))
|
||||
>x4 : Symbol(x4, Decl(mappedTypesArraysTuples.ts, 68, 7))
|
||||
>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12))
|
||||
>b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22))
|
||||
>c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42))
|
||||
>d : Symbol(d, Decl(mappedTypesArraysTuples.ts, 64, 55))
|
||||
}
|
||||
|
||||
function f2<T extends any[]>(a: Boxified<T>) {
|
||||
>f2 : Symbol(f2, Decl(mappedTypesArraysTuples.ts, 61, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 63, 12))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 63, 29))
|
||||
>f2 : Symbol(f2, Decl(mappedTypesArraysTuples.ts, 69, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 71, 12))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 71, 29))
|
||||
>Boxified : Symbol(Boxified, Decl(mappedTypesArraysTuples.ts, 0, 27))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 63, 12))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 71, 12))
|
||||
|
||||
let x: Box<any> | undefined = a.pop();
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 64, 7))
|
||||
>x : Symbol(x, Decl(mappedTypesArraysTuples.ts, 72, 7))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
>a.pop : Symbol(Array.pop, Decl(lib.es5.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 63, 29))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 71, 29))
|
||||
>pop : Symbol(Array.pop, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
let y: Box<any>[] = a.concat(a);
|
||||
>y : Symbol(y, Decl(mappedTypesArraysTuples.ts, 65, 7))
|
||||
>y : Symbol(y, Decl(mappedTypesArraysTuples.ts, 73, 7))
|
||||
>Box : Symbol(Box, Decl(mappedTypesArraysTuples.ts, 0, 0))
|
||||
>a.concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 63, 29))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 71, 29))
|
||||
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 63, 29))
|
||||
>a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 71, 29))
|
||||
}
|
||||
|
||||
// Repro from #26163
|
||||
|
||||
type ElementType<T> = T extends Array<infer U> ? U : never;
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 66, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 70, 17))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 70, 17))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 74, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 78, 17))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 78, 17))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 70, 43))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 70, 43))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 78, 43))
|
||||
>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 78, 43))
|
||||
|
||||
type Mapped<T> = { [K in keyof T]: T[K] };
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 71, 12))
|
||||
>K : Symbol(K, Decl(mappedTypesArraysTuples.ts, 71, 20))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 71, 12))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 71, 12))
|
||||
>K : Symbol(K, Decl(mappedTypesArraysTuples.ts, 71, 20))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 79, 12))
|
||||
>K : Symbol(K, Decl(mappedTypesArraysTuples.ts, 79, 20))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 79, 12))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 79, 12))
|
||||
>K : Symbol(K, Decl(mappedTypesArraysTuples.ts, 79, 20))
|
||||
|
||||
type F<T> = ElementType<Mapped<T>>;
|
||||
>F : Symbol(F, Decl(mappedTypesArraysTuples.ts, 71, 42))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 73, 7))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 66, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 73, 7))
|
||||
>F : Symbol(F, Decl(mappedTypesArraysTuples.ts, 79, 42))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 81, 7))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 74, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 81, 7))
|
||||
|
||||
type R1 = F<[string, number, boolean]>; // string | number | boolean
|
||||
>R1 : Symbol(R1, Decl(mappedTypesArraysTuples.ts, 73, 35))
|
||||
>F : Symbol(F, Decl(mappedTypesArraysTuples.ts, 71, 42))
|
||||
>R1 : Symbol(R1, Decl(mappedTypesArraysTuples.ts, 81, 35))
|
||||
>F : Symbol(F, Decl(mappedTypesArraysTuples.ts, 79, 42))
|
||||
|
||||
type R2 = ElementType<Mapped<[string, number, boolean]>>; // string | number | boolean
|
||||
>R2 : Symbol(R2, Decl(mappedTypesArraysTuples.ts, 74, 39))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 66, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>R2 : Symbol(R2, Decl(mappedTypesArraysTuples.ts, 82, 39))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 74, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
|
||||
// Repro from #26163
|
||||
|
||||
declare function acceptArray(arr: any[]): void;
|
||||
>acceptArray : Symbol(acceptArray, Decl(mappedTypesArraysTuples.ts, 75, 57))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 79, 29))
|
||||
>acceptArray : Symbol(acceptArray, Decl(mappedTypesArraysTuples.ts, 83, 57))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 87, 29))
|
||||
|
||||
declare function mapArray<T extends any[]>(arr: T): Mapped<T>;
|
||||
>mapArray : Symbol(mapArray, Decl(mappedTypesArraysTuples.ts, 79, 47))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 80, 26))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 80, 43))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 80, 26))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 80, 26))
|
||||
>mapArray : Symbol(mapArray, Decl(mappedTypesArraysTuples.ts, 87, 47))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 88, 26))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 88, 43))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 88, 26))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 88, 26))
|
||||
|
||||
function acceptMappedArray<T extends any[]>(arr: T) {
|
||||
>acceptMappedArray : Symbol(acceptMappedArray, Decl(mappedTypesArraysTuples.ts, 80, 62))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 81, 27))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 81, 44))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 81, 27))
|
||||
>acceptMappedArray : Symbol(acceptMappedArray, Decl(mappedTypesArraysTuples.ts, 88, 62))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 89, 27))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 89, 44))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 89, 27))
|
||||
|
||||
acceptArray(mapArray(arr));
|
||||
>acceptArray : Symbol(acceptArray, Decl(mappedTypesArraysTuples.ts, 75, 57))
|
||||
>mapArray : Symbol(mapArray, Decl(mappedTypesArraysTuples.ts, 79, 47))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 81, 44))
|
||||
>acceptArray : Symbol(acceptArray, Decl(mappedTypesArraysTuples.ts, 83, 57))
|
||||
>mapArray : Symbol(mapArray, Decl(mappedTypesArraysTuples.ts, 87, 47))
|
||||
>arr : Symbol(arr, Decl(mappedTypesArraysTuples.ts, 89, 44))
|
||||
}
|
||||
|
||||
// Repro from #26163
|
||||
|
||||
type Unconstrained<T> = ElementType<Mapped<T>>;
|
||||
>Unconstrained : Symbol(Unconstrained, Decl(mappedTypesArraysTuples.ts, 83, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 87, 19))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 66, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 87, 19))
|
||||
>Unconstrained : Symbol(Unconstrained, Decl(mappedTypesArraysTuples.ts, 91, 1))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 95, 19))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 74, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 95, 19))
|
||||
|
||||
type T1 = Unconstrained<[string, number, boolean]>; // string | number | boolean
|
||||
>T1 : Symbol(T1, Decl(mappedTypesArraysTuples.ts, 87, 47))
|
||||
>Unconstrained : Symbol(Unconstrained, Decl(mappedTypesArraysTuples.ts, 83, 1))
|
||||
>T1 : Symbol(T1, Decl(mappedTypesArraysTuples.ts, 95, 47))
|
||||
>Unconstrained : Symbol(Unconstrained, Decl(mappedTypesArraysTuples.ts, 91, 1))
|
||||
|
||||
type Constrained<T extends any[]> = ElementType<Mapped<T>>;
|
||||
>Constrained : Symbol(Constrained, Decl(mappedTypesArraysTuples.ts, 88, 51))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 90, 17))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 66, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 70, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 90, 17))
|
||||
>Constrained : Symbol(Constrained, Decl(mappedTypesArraysTuples.ts, 96, 51))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 98, 17))
|
||||
>ElementType : Symbol(ElementType, Decl(mappedTypesArraysTuples.ts, 74, 1))
|
||||
>Mapped : Symbol(Mapped, Decl(mappedTypesArraysTuples.ts, 78, 59))
|
||||
>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 98, 17))
|
||||
|
||||
type T2 = Constrained<[string, number, boolean]>; // string | number | boolean
|
||||
>T2 : Symbol(T2, Decl(mappedTypesArraysTuples.ts, 90, 59))
|
||||
>Constrained : Symbol(Constrained, Decl(mappedTypesArraysTuples.ts, 88, 51))
|
||||
>T2 : Symbol(T2, Decl(mappedTypesArraysTuples.ts, 98, 59))
|
||||
>Constrained : Symbol(Constrained, Decl(mappedTypesArraysTuples.ts, 96, 51))
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ type T12 = Required<string[]>;
|
||||
>T12 : string[]
|
||||
|
||||
type T13 = Boxified<ReadonlyArray<string>>;
|
||||
>T13 : ReadonlyArray<Box<string>>
|
||||
>T13 : readonly Box<string>[]
|
||||
|
||||
type T14 = Partial<ReadonlyArray<string>>;
|
||||
>T14 : ReadonlyArray<string | undefined>
|
||||
>T14 : readonly (string | undefined)[]
|
||||
|
||||
type T15 = Required<ReadonlyArray<string>>;
|
||||
>T15 : ReadonlyArray<string>
|
||||
>T15 : readonly string[]
|
||||
|
||||
type T20 = Boxified<(string | undefined)[]>;
|
||||
>T20 : Box<string | undefined>[]
|
||||
@@ -43,13 +43,13 @@ type T22 = Required<(string | undefined)[]>;
|
||||
>T22 : string[]
|
||||
|
||||
type T23 = Boxified<ReadonlyArray<string | undefined>>;
|
||||
>T23 : ReadonlyArray<Box<string | undefined>>
|
||||
>T23 : readonly Box<string | undefined>[]
|
||||
|
||||
type T24 = Partial<ReadonlyArray<string | undefined>>;
|
||||
>T24 : ReadonlyArray<string | undefined>
|
||||
>T24 : readonly (string | undefined)[]
|
||||
|
||||
type T25 = Required<ReadonlyArray<string | undefined>>;
|
||||
>T25 : ReadonlyArray<string>
|
||||
>T25 : readonly string[]
|
||||
|
||||
type T30 = Boxified<Partial<string[]>>;
|
||||
>T30 : Box<string | undefined>[]
|
||||
@@ -66,7 +66,25 @@ type B = { b: string };
|
||||
>b : string
|
||||
|
||||
type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>;
|
||||
>T40 : string | Box<string>[] | Boxified<A> | Box<A>[] | ReadonlyArray<Box<A>> | [Box<A>, Box<B>]
|
||||
>T40 : string | Box<string>[] | Boxified<A> | Box<A>[] | readonly Box<A>[] | [Box<A>, Box<B>]
|
||||
|
||||
type ReadWrite<T> = { -readonly [P in keyof T] : T[P] };
|
||||
>ReadWrite : ReadWrite<T>
|
||||
|
||||
type T50 = Readonly<string[]>;
|
||||
>T50 : readonly string[]
|
||||
|
||||
type T51 = Readonly<[number, number]>;
|
||||
>T51 : readonly [number, number]
|
||||
|
||||
type T52 = Partial<Readonly<string[]>>;
|
||||
>T52 : readonly (string | undefined)[]
|
||||
|
||||
type T53 = Readonly<Partial<string[]>>;
|
||||
>T53 : readonly (string | undefined)[]
|
||||
|
||||
type T54 = ReadWrite<Required<T53>>;
|
||||
>T54 : string[]
|
||||
|
||||
declare function unboxify<T>(x: Boxified<T>): T;
|
||||
>unboxify : <T>(x: Boxified<T>) => T
|
||||
|
||||
@@ -117,6 +117,6 @@ function f(x = 0, b = false) {
|
||||
>1 : 1
|
||||
}
|
||||
function f2(_: ReadonlyArray<number>): void {}
|
||||
>f2 : (_: ReadonlyArray<number>) => void
|
||||
>_ : ReadonlyArray<number>
|
||||
>f2 : (_: readonly number[]) => void
|
||||
>_ : readonly number[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/objectFreeze.ts(9,1): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/objectFreeze.ts(9,1): error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
|
||||
tests/cases/compiler/objectFreeze.ts(9,1): error TS2542: Index signature in type 'readonly number[]' only permits reading.
|
||||
tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' because it is a read-only property.
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' b
|
||||
~~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
~~~~
|
||||
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
|
||||
!!! error TS2542: Index signature in type 'readonly number[]' only permits reading.
|
||||
|
||||
const o = Object.freeze({ a: 1, b: "string" });
|
||||
o.b = o.a.toString();
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
const f = Object.freeze(function foo(a: number, b: string) { return false; });
|
||||
>f : (a: number, b: string) => false
|
||||
>Object.freeze(function foo(a: number, b: string) { return false; }) : (a: number, b: string) => false
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>function foo(a: number, b: string) { return false; } : (a: number, b: string) => false
|
||||
>foo : (a: number, b: string) => false
|
||||
>a : number
|
||||
@@ -26,9 +26,9 @@ class C { constructor(a: number) { } }
|
||||
const c = Object.freeze(C);
|
||||
>c : typeof C
|
||||
>Object.freeze(C) : typeof C
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>C : typeof C
|
||||
|
||||
new c(1);
|
||||
@@ -37,11 +37,11 @@ new c(1);
|
||||
>1 : 1
|
||||
|
||||
const a = Object.freeze([1, 2, 3]);
|
||||
>a : ReadonlyArray<number>
|
||||
>Object.freeze([1, 2, 3]) : ReadonlyArray<number>
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>a : readonly number[]
|
||||
>Object.freeze([1, 2, 3]) : readonly number[]
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>[1, 2, 3] : number[]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
@@ -50,21 +50,21 @@ const a = Object.freeze([1, 2, 3]);
|
||||
a[0] = a[2].toString();
|
||||
>a[0] = a[2].toString() : string
|
||||
>a[0] : number
|
||||
>a : ReadonlyArray<number>
|
||||
>a : readonly number[]
|
||||
>0 : 0
|
||||
>a[2].toString() : string
|
||||
>a[2].toString : (radix?: number) => string
|
||||
>a[2] : number
|
||||
>a : ReadonlyArray<number>
|
||||
>a : readonly number[]
|
||||
>2 : 2
|
||||
>toString : (radix?: number) => string
|
||||
|
||||
const o = Object.freeze({ a: 1, b: "string" });
|
||||
>o : Readonly<{ a: number; b: string; }>
|
||||
>Object.freeze({ a: 1, b: "string" }) : Readonly<{ a: number; b: string; }>
|
||||
>Object.freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object.freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>Object : ObjectConstructor
|
||||
>freeze : { <T>(a: T[]): ReadonlyArray<T>; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>freeze : { <T>(a: T[]): readonly T[]; <T extends Function>(f: T): T; <T>(o: T): Readonly<T>; }
|
||||
>{ a: 1, b: "string" } : { a: number; b: string; }
|
||||
>a : number
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(9,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(10,15): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(11,12): error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(14,5): error TS2740: Type 'readonly string[]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(16,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(20,5): error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(21,5): error TS2740: Type 'readonly string[]' is missing the following properties from type '[string, string]': 0, 1, pop, push, and 5 more.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(22,5): error TS2740: Type 'readonly [string, string]' is missing the following properties from type '[string, string]': pop, push, reverse, shift, and 3 more.
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(23,5): error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts (10 errors) ====
|
||||
type T10 = string[];
|
||||
type T11 = Array<string>;
|
||||
type T12 = readonly string[];
|
||||
type T13 = ReadonlyArray<string>;
|
||||
|
||||
type T20 = [number, number];
|
||||
type T21 = readonly [number, number];
|
||||
|
||||
type T30 = readonly string; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
type T31<T> = readonly T; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
type T32 = readonly readonly string[]; // Error
|
||||
~~~~~~~~
|
||||
!!! error TS1354: 'readonly' type modifier is only permitted on array and tuple types.
|
||||
|
||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||
ma = ra; // Error
|
||||
~~
|
||||
!!! error TS2740: Type 'readonly string[]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||
ma = mt;
|
||||
ma = rt; // Error
|
||||
~~
|
||||
!!! error TS2740: Type 'readonly [string, string]' is missing the following properties from type 'string[]': pop, push, reverse, shift, and 3 more.
|
||||
ra = ma;
|
||||
ra = mt;
|
||||
ra = rt;
|
||||
mt = ma; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'string[]' is missing the following properties from type '[string, string]': 0, 1
|
||||
mt = ra; // Error
|
||||
~~
|
||||
!!! error TS2740: Type 'readonly string[]' is missing the following properties from type '[string, string]': 0, 1, pop, push, and 5 more.
|
||||
mt = rt; // Error
|
||||
~~
|
||||
!!! error TS2740: Type 'readonly [string, string]' is missing the following properties from type '[string, string]': pop, push, reverse, shift, and 3 more.
|
||||
rt = ma; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
rt = ra; // Error
|
||||
~~
|
||||
!!! error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1
|
||||
rt = mt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//// [readonlyArraysAndTuples.ts]
|
||||
type T10 = string[];
|
||||
type T11 = Array<string>;
|
||||
type T12 = readonly string[];
|
||||
type T13 = ReadonlyArray<string>;
|
||||
|
||||
type T20 = [number, number];
|
||||
type T21 = readonly [number, number];
|
||||
|
||||
type T30 = readonly string; // Error
|
||||
type T31<T> = readonly T; // Error
|
||||
type T32 = readonly readonly string[]; // Error
|
||||
|
||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||
ma = ra; // Error
|
||||
ma = mt;
|
||||
ma = rt; // Error
|
||||
ra = ma;
|
||||
ra = mt;
|
||||
ra = rt;
|
||||
mt = ma; // Error
|
||||
mt = ra; // Error
|
||||
mt = rt; // Error
|
||||
rt = ma; // Error
|
||||
rt = ra; // Error
|
||||
rt = mt;
|
||||
}
|
||||
|
||||
|
||||
//// [readonlyArraysAndTuples.js]
|
||||
"use strict";
|
||||
function f1(ma, ra, mt, rt) {
|
||||
ma = ra; // Error
|
||||
ma = mt;
|
||||
ma = rt; // Error
|
||||
ra = ma;
|
||||
ra = mt;
|
||||
ra = rt;
|
||||
mt = ma; // Error
|
||||
mt = ra; // Error
|
||||
mt = rt; // Error
|
||||
rt = ma; // Error
|
||||
rt = ra; // Error
|
||||
rt = mt;
|
||||
}
|
||||
|
||||
|
||||
//// [readonlyArraysAndTuples.d.ts]
|
||||
declare type T10 = string[];
|
||||
declare type T11 = Array<string>;
|
||||
declare type T12 = readonly string[];
|
||||
declare type T13 = ReadonlyArray<string>;
|
||||
declare type T20 = [number, number];
|
||||
declare type T21 = readonly [number, number];
|
||||
declare type T30 = readonly string;
|
||||
declare type T31<T> = readonly T;
|
||||
declare type T32 = readonly readonly string[];
|
||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): void;
|
||||
@@ -0,0 +1,88 @@
|
||||
=== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts ===
|
||||
type T10 = string[];
|
||||
>T10 : Symbol(T10, Decl(readonlyArraysAndTuples.ts, 0, 0))
|
||||
|
||||
type T11 = Array<string>;
|
||||
>T11 : Symbol(T11, Decl(readonlyArraysAndTuples.ts, 0, 20))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T12 = readonly string[];
|
||||
>T12 : Symbol(T12, Decl(readonlyArraysAndTuples.ts, 1, 25))
|
||||
|
||||
type T13 = ReadonlyArray<string>;
|
||||
>T13 : Symbol(T13, Decl(readonlyArraysAndTuples.ts, 2, 29))
|
||||
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T20 = [number, number];
|
||||
>T20 : Symbol(T20, Decl(readonlyArraysAndTuples.ts, 3, 33))
|
||||
|
||||
type T21 = readonly [number, number];
|
||||
>T21 : Symbol(T21, Decl(readonlyArraysAndTuples.ts, 5, 28))
|
||||
|
||||
type T30 = readonly string; // Error
|
||||
>T30 : Symbol(T30, Decl(readonlyArraysAndTuples.ts, 6, 37))
|
||||
|
||||
type T31<T> = readonly T; // Error
|
||||
>T31 : Symbol(T31, Decl(readonlyArraysAndTuples.ts, 8, 27))
|
||||
>T : Symbol(T, Decl(readonlyArraysAndTuples.ts, 9, 9))
|
||||
>T : Symbol(T, Decl(readonlyArraysAndTuples.ts, 9, 9))
|
||||
|
||||
type T32 = readonly readonly string[]; // Error
|
||||
>T32 : Symbol(T32, Decl(readonlyArraysAndTuples.ts, 9, 25))
|
||||
|
||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||
>f1 : Symbol(f1, Decl(readonlyArraysAndTuples.ts, 10, 38))
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
|
||||
ma = ra; // Error
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
|
||||
ma = mt;
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
|
||||
ma = rt; // Error
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
|
||||
ra = ma;
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
|
||||
ra = mt;
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
|
||||
ra = rt;
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
|
||||
mt = ma; // Error
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
|
||||
mt = ra; // Error
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
|
||||
mt = rt; // Error
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
|
||||
rt = ma; // Error
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples.ts, 12, 12))
|
||||
|
||||
rt = ra; // Error
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples.ts, 12, 25))
|
||||
|
||||
rt = mt;
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples.ts, 12, 70))
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 12, 48))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
=== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts ===
|
||||
type T10 = string[];
|
||||
>T10 : string[]
|
||||
|
||||
type T11 = Array<string>;
|
||||
>T11 : string[]
|
||||
|
||||
type T12 = readonly string[];
|
||||
>T12 : readonly string[]
|
||||
|
||||
type T13 = ReadonlyArray<string>;
|
||||
>T13 : readonly string[]
|
||||
|
||||
type T20 = [number, number];
|
||||
>T20 : [number, number]
|
||||
|
||||
type T21 = readonly [number, number];
|
||||
>T21 : readonly [number, number]
|
||||
|
||||
type T30 = readonly string; // Error
|
||||
>T30 : string
|
||||
|
||||
type T31<T> = readonly T; // Error
|
||||
>T31 : T
|
||||
|
||||
type T32 = readonly readonly string[]; // Error
|
||||
>T32 : readonly string[]
|
||||
|
||||
function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
|
||||
>f1 : (ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) => void
|
||||
>ma : string[]
|
||||
>ra : readonly string[]
|
||||
>mt : [string, string]
|
||||
>rt : readonly [string, string]
|
||||
|
||||
ma = ra; // Error
|
||||
>ma = ra : readonly string[]
|
||||
>ma : string[]
|
||||
>ra : readonly string[]
|
||||
|
||||
ma = mt;
|
||||
>ma = mt : [string, string]
|
||||
>ma : string[]
|
||||
>mt : [string, string]
|
||||
|
||||
ma = rt; // Error
|
||||
>ma = rt : readonly [string, string]
|
||||
>ma : string[]
|
||||
>rt : readonly [string, string]
|
||||
|
||||
ra = ma;
|
||||
>ra = ma : string[]
|
||||
>ra : readonly string[]
|
||||
>ma : string[]
|
||||
|
||||
ra = mt;
|
||||
>ra = mt : [string, string]
|
||||
>ra : readonly string[]
|
||||
>mt : [string, string]
|
||||
|
||||
ra = rt;
|
||||
>ra = rt : readonly [string, string]
|
||||
>ra : readonly string[]
|
||||
>rt : readonly [string, string]
|
||||
|
||||
mt = ma; // Error
|
||||
>mt = ma : string[]
|
||||
>mt : [string, string]
|
||||
>ma : string[]
|
||||
|
||||
mt = ra; // Error
|
||||
>mt = ra : readonly string[]
|
||||
>mt : [string, string]
|
||||
>ra : readonly string[]
|
||||
|
||||
mt = rt; // Error
|
||||
>mt = rt : readonly [string, string]
|
||||
>mt : [string, string]
|
||||
>rt : readonly [string, string]
|
||||
|
||||
rt = ma; // Error
|
||||
>rt = ma : string[]
|
||||
>rt : readonly [string, string]
|
||||
>ma : string[]
|
||||
|
||||
rt = ra; // Error
|
||||
>rt = ra : readonly string[]
|
||||
>rt : readonly [string, string]
|
||||
>ra : readonly string[]
|
||||
|
||||
rt = mt;
|
||||
>rt = mt : [string, string]
|
||||
>rt : readonly [string, string]
|
||||
>mt : [string, string]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//// [readonlyArraysAndTuples2.ts]
|
||||
type T10 = string[];
|
||||
type T11 = Array<string>;
|
||||
type T12 = readonly string[];
|
||||
type T13 = ReadonlyArray<string>;
|
||||
|
||||
type T20 = [number, number];
|
||||
type T21 = readonly [number, number];
|
||||
|
||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): readonly [string, string];
|
||||
|
||||
declare const someDec: any;
|
||||
|
||||
class A {
|
||||
@someDec
|
||||
j: readonly string[] = [];
|
||||
@someDec
|
||||
k: readonly [string, number] = ['foo', 42];
|
||||
}
|
||||
|
||||
|
||||
//// [readonlyArraysAndTuples2.js]
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
this.j = [];
|
||||
this.k = ['foo', 42];
|
||||
}
|
||||
__decorate([
|
||||
someDec,
|
||||
__metadata("design:type", Array)
|
||||
], A.prototype, "j");
|
||||
__decorate([
|
||||
someDec,
|
||||
__metadata("design:type", Array)
|
||||
], A.prototype, "k");
|
||||
return A;
|
||||
}());
|
||||
|
||||
|
||||
//// [readonlyArraysAndTuples2.d.ts]
|
||||
declare type T10 = string[];
|
||||
declare type T11 = Array<string>;
|
||||
declare type T12 = readonly string[];
|
||||
declare type T13 = ReadonlyArray<string>;
|
||||
declare type T20 = [number, number];
|
||||
declare type T21 = readonly [number, number];
|
||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): readonly [string, string];
|
||||
declare const someDec: any;
|
||||
declare class A {
|
||||
j: readonly string[];
|
||||
k: readonly [string, number];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
=== tests/cases/conformance/types/tuple/readonlyArraysAndTuples2.ts ===
|
||||
type T10 = string[];
|
||||
>T10 : Symbol(T10, Decl(readonlyArraysAndTuples2.ts, 0, 0))
|
||||
|
||||
type T11 = Array<string>;
|
||||
>T11 : Symbol(T11, Decl(readonlyArraysAndTuples2.ts, 0, 20))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T12 = readonly string[];
|
||||
>T12 : Symbol(T12, Decl(readonlyArraysAndTuples2.ts, 1, 25))
|
||||
|
||||
type T13 = ReadonlyArray<string>;
|
||||
>T13 : Symbol(T13, Decl(readonlyArraysAndTuples2.ts, 2, 29))
|
||||
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type T20 = [number, number];
|
||||
>T20 : Symbol(T20, Decl(readonlyArraysAndTuples2.ts, 3, 33))
|
||||
|
||||
type T21 = readonly [number, number];
|
||||
>T21 : Symbol(T21, Decl(readonlyArraysAndTuples2.ts, 5, 28))
|
||||
|
||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): readonly [string, string];
|
||||
>f1 : Symbol(f1, Decl(readonlyArraysAndTuples2.ts, 6, 37))
|
||||
>ma : Symbol(ma, Decl(readonlyArraysAndTuples2.ts, 8, 20))
|
||||
>ra : Symbol(ra, Decl(readonlyArraysAndTuples2.ts, 8, 33))
|
||||
>mt : Symbol(mt, Decl(readonlyArraysAndTuples2.ts, 8, 56))
|
||||
>rt : Symbol(rt, Decl(readonlyArraysAndTuples2.ts, 8, 78))
|
||||
|
||||
declare const someDec: any;
|
||||
>someDec : Symbol(someDec, Decl(readonlyArraysAndTuples2.ts, 10, 13))
|
||||
|
||||
class A {
|
||||
>A : Symbol(A, Decl(readonlyArraysAndTuples2.ts, 10, 27))
|
||||
|
||||
@someDec
|
||||
>someDec : Symbol(someDec, Decl(readonlyArraysAndTuples2.ts, 10, 13))
|
||||
|
||||
j: readonly string[] = [];
|
||||
>j : Symbol(A.j, Decl(readonlyArraysAndTuples2.ts, 12, 9))
|
||||
|
||||
@someDec
|
||||
>someDec : Symbol(someDec, Decl(readonlyArraysAndTuples2.ts, 10, 13))
|
||||
|
||||
k: readonly [string, number] = ['foo', 42];
|
||||
>k : Symbol(A.k, Decl(readonlyArraysAndTuples2.ts, 14, 28))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
=== tests/cases/conformance/types/tuple/readonlyArraysAndTuples2.ts ===
|
||||
type T10 = string[];
|
||||
>T10 : string[]
|
||||
|
||||
type T11 = Array<string>;
|
||||
>T11 : string[]
|
||||
|
||||
type T12 = readonly string[];
|
||||
>T12 : readonly string[]
|
||||
|
||||
type T13 = ReadonlyArray<string>;
|
||||
>T13 : readonly string[]
|
||||
|
||||
type T20 = [number, number];
|
||||
>T20 : [number, number]
|
||||
|
||||
type T21 = readonly [number, number];
|
||||
>T21 : readonly [number, number]
|
||||
|
||||
declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): readonly [string, string];
|
||||
>f1 : (ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) => readonly [string, string]
|
||||
>ma : string[]
|
||||
>ra : readonly string[]
|
||||
>mt : [string, string]
|
||||
>rt : readonly [string, string]
|
||||
|
||||
declare const someDec: any;
|
||||
>someDec : any
|
||||
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
@someDec
|
||||
>someDec : any
|
||||
|
||||
j: readonly string[] = [];
|
||||
>j : readonly string[]
|
||||
>[] : never[]
|
||||
|
||||
@someDec
|
||||
>someDec : any
|
||||
|
||||
k: readonly [string, number] = ['foo', 42];
|
||||
>k : readonly [string, number]
|
||||
>['foo', 42] : [string, number]
|
||||
>'foo' : "foo"
|
||||
>42 : 42
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts(8,5): error TS2556: Expected 2 arguments, but got 0 or more.
|
||||
tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts(20,5): error TS2554: Expected 2 arguments, but got 3.
|
||||
tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts(25,5): error TS2542: Index signature in type 'readonly string[]' only permits reading.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts (3 errors) ====
|
||||
function f0(a: string, b: string) {
|
||||
f0(a, b);
|
||||
f1(a, b);
|
||||
f2(a, b);
|
||||
}
|
||||
|
||||
function f1(...args: readonly string[]) {
|
||||
f0(...args); // Error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2556: Expected 2 arguments, but got 0 or more.
|
||||
!!! related TS6210 tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts:1:13: An argument for 'a' was not provided.
|
||||
f1('abc', 'def');
|
||||
f1('abc', ...args);
|
||||
f1(...args);
|
||||
}
|
||||
|
||||
function f2(...args: readonly [string, string]) {
|
||||
f0(...args);
|
||||
f1('abc', 'def');
|
||||
f1('abc', ...args);
|
||||
f1(...args);
|
||||
f2('abc', 'def');
|
||||
f2('abc', ...args); // Error
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2554: Expected 2 arguments, but got 3.
|
||||
f2(...args);
|
||||
}
|
||||
|
||||
function f4(...args: readonly string[]) {
|
||||
args[0] = 'abc'; // Error
|
||||
~~~~~~~
|
||||
!!! error TS2542: Index signature in type 'readonly string[]' only permits reading.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//// [readonlyRestParameters.ts]
|
||||
function f0(a: string, b: string) {
|
||||
f0(a, b);
|
||||
f1(a, b);
|
||||
f2(a, b);
|
||||
}
|
||||
|
||||
function f1(...args: readonly string[]) {
|
||||
f0(...args); // Error
|
||||
f1('abc', 'def');
|
||||
f1('abc', ...args);
|
||||
f1(...args);
|
||||
}
|
||||
|
||||
function f2(...args: readonly [string, string]) {
|
||||
f0(...args);
|
||||
f1('abc', 'def');
|
||||
f1('abc', ...args);
|
||||
f1(...args);
|
||||
f2('abc', 'def');
|
||||
f2('abc', ...args); // Error
|
||||
f2(...args);
|
||||
}
|
||||
|
||||
function f4(...args: readonly string[]) {
|
||||
args[0] = 'abc'; // Error
|
||||
}
|
||||
|
||||
|
||||
//// [readonlyRestParameters.js]
|
||||
"use strict";
|
||||
function f0(a, b) {
|
||||
f0(a, b);
|
||||
f1(a, b);
|
||||
f2(a, b);
|
||||
}
|
||||
function f1() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
f0.apply(void 0, args); // Error
|
||||
f1('abc', 'def');
|
||||
f1.apply(void 0, ['abc'].concat(args));
|
||||
f1.apply(void 0, args);
|
||||
}
|
||||
function f2() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
f0.apply(void 0, args);
|
||||
f1('abc', 'def');
|
||||
f1.apply(void 0, ['abc'].concat(args));
|
||||
f1.apply(void 0, args);
|
||||
f2('abc', 'def');
|
||||
f2.apply(void 0, ['abc'].concat(args)); // Error
|
||||
f2.apply(void 0, args);
|
||||
}
|
||||
function f4() {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
args[0] = 'abc'; // Error
|
||||
}
|
||||
|
||||
|
||||
//// [readonlyRestParameters.d.ts]
|
||||
declare function f0(a: string, b: string): void;
|
||||
declare function f1(...args: readonly string[]): void;
|
||||
declare function f2(...args: readonly [string, string]): void;
|
||||
declare function f4(...args: readonly string[]): void;
|
||||
@@ -0,0 +1,81 @@
|
||||
=== tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts ===
|
||||
function f0(a: string, b: string) {
|
||||
>f0 : Symbol(f0, Decl(readonlyRestParameters.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(readonlyRestParameters.ts, 0, 12))
|
||||
>b : Symbol(b, Decl(readonlyRestParameters.ts, 0, 22))
|
||||
|
||||
f0(a, b);
|
||||
>f0 : Symbol(f0, Decl(readonlyRestParameters.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(readonlyRestParameters.ts, 0, 12))
|
||||
>b : Symbol(b, Decl(readonlyRestParameters.ts, 0, 22))
|
||||
|
||||
f1(a, b);
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>a : Symbol(a, Decl(readonlyRestParameters.ts, 0, 12))
|
||||
>b : Symbol(b, Decl(readonlyRestParameters.ts, 0, 22))
|
||||
|
||||
f2(a, b);
|
||||
>f2 : Symbol(f2, Decl(readonlyRestParameters.ts, 11, 1))
|
||||
>a : Symbol(a, Decl(readonlyRestParameters.ts, 0, 12))
|
||||
>b : Symbol(b, Decl(readonlyRestParameters.ts, 0, 22))
|
||||
}
|
||||
|
||||
function f1(...args: readonly string[]) {
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 6, 12))
|
||||
|
||||
f0(...args); // Error
|
||||
>f0 : Symbol(f0, Decl(readonlyRestParameters.ts, 0, 0))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 6, 12))
|
||||
|
||||
f1('abc', 'def');
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
|
||||
f1('abc', ...args);
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 6, 12))
|
||||
|
||||
f1(...args);
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 6, 12))
|
||||
}
|
||||
|
||||
function f2(...args: readonly [string, string]) {
|
||||
>f2 : Symbol(f2, Decl(readonlyRestParameters.ts, 11, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
|
||||
f0(...args);
|
||||
>f0 : Symbol(f0, Decl(readonlyRestParameters.ts, 0, 0))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
|
||||
f1('abc', 'def');
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
|
||||
f1('abc', ...args);
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
|
||||
f1(...args);
|
||||
>f1 : Symbol(f1, Decl(readonlyRestParameters.ts, 4, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
|
||||
f2('abc', 'def');
|
||||
>f2 : Symbol(f2, Decl(readonlyRestParameters.ts, 11, 1))
|
||||
|
||||
f2('abc', ...args); // Error
|
||||
>f2 : Symbol(f2, Decl(readonlyRestParameters.ts, 11, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
|
||||
f2(...args);
|
||||
>f2 : Symbol(f2, Decl(readonlyRestParameters.ts, 11, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 13, 12))
|
||||
}
|
||||
|
||||
function f4(...args: readonly string[]) {
|
||||
>f4 : Symbol(f4, Decl(readonlyRestParameters.ts, 21, 1))
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 23, 12))
|
||||
|
||||
args[0] = 'abc'; // Error
|
||||
>args : Symbol(args, Decl(readonlyRestParameters.ts, 23, 12))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
=== tests/cases/conformance/es6/restParameters/readonlyRestParameters.ts ===
|
||||
function f0(a: string, b: string) {
|
||||
>f0 : (a: string, b: string) => void
|
||||
>a : string
|
||||
>b : string
|
||||
|
||||
f0(a, b);
|
||||
>f0(a, b) : void
|
||||
>f0 : (a: string, b: string) => void
|
||||
>a : string
|
||||
>b : string
|
||||
|
||||
f1(a, b);
|
||||
>f1(a, b) : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>a : string
|
||||
>b : string
|
||||
|
||||
f2(a, b);
|
||||
>f2(a, b) : void
|
||||
>f2 : (args_0: string, args_1: string) => void
|
||||
>a : string
|
||||
>b : string
|
||||
}
|
||||
|
||||
function f1(...args: readonly string[]) {
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>args : readonly string[]
|
||||
|
||||
f0(...args); // Error
|
||||
>f0(...args) : void
|
||||
>f0 : (a: string, b: string) => void
|
||||
>...args : string
|
||||
>args : readonly string[]
|
||||
|
||||
f1('abc', 'def');
|
||||
>f1('abc', 'def') : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>'abc' : "abc"
|
||||
>'def' : "def"
|
||||
|
||||
f1('abc', ...args);
|
||||
>f1('abc', ...args) : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>'abc' : "abc"
|
||||
>...args : string
|
||||
>args : readonly string[]
|
||||
|
||||
f1(...args);
|
||||
>f1(...args) : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>...args : string
|
||||
>args : readonly string[]
|
||||
}
|
||||
|
||||
function f2(...args: readonly [string, string]) {
|
||||
>f2 : (args_0: string, args_1: string) => void
|
||||
>args : readonly [string, string]
|
||||
|
||||
f0(...args);
|
||||
>f0(...args) : void
|
||||
>f0 : (a: string, b: string) => void
|
||||
>...args : string
|
||||
>args : readonly [string, string]
|
||||
|
||||
f1('abc', 'def');
|
||||
>f1('abc', 'def') : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>'abc' : "abc"
|
||||
>'def' : "def"
|
||||
|
||||
f1('abc', ...args);
|
||||
>f1('abc', ...args) : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>'abc' : "abc"
|
||||
>...args : string
|
||||
>args : readonly [string, string]
|
||||
|
||||
f1(...args);
|
||||
>f1(...args) : void
|
||||
>f1 : (...args: readonly string[]) => void
|
||||
>...args : string
|
||||
>args : readonly [string, string]
|
||||
|
||||
f2('abc', 'def');
|
||||
>f2('abc', 'def') : void
|
||||
>f2 : (args_0: string, args_1: string) => void
|
||||
>'abc' : "abc"
|
||||
>'def' : "def"
|
||||
|
||||
f2('abc', ...args); // Error
|
||||
>f2('abc', ...args) : void
|
||||
>f2 : (args_0: string, args_1: string) => void
|
||||
>'abc' : "abc"
|
||||
>...args : string
|
||||
>args : readonly [string, string]
|
||||
|
||||
f2(...args);
|
||||
>f2(...args) : void
|
||||
>f2 : (args_0: string, args_1: string) => void
|
||||
>...args : string
|
||||
>args : readonly [string, string]
|
||||
}
|
||||
|
||||
function f4(...args: readonly string[]) {
|
||||
>f4 : (...args: readonly string[]) => void
|
||||
>args : readonly string[]
|
||||
|
||||
args[0] = 'abc'; // Error
|
||||
>args[0] = 'abc' : "abc"
|
||||
>args[0] : string
|
||||
>args : readonly string[]
|
||||
>0 : 0
|
||||
>'abc' : "abc"
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use(x);
|
||||
//// [f.js]
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
/// <reference path="f.d.ts"/>
|
||||
exports.__esModule = true;
|
||||
var test_1 = require("test");
|
||||
use(test_1.x);
|
||||
|
||||
@@ -97,13 +97,13 @@ const x11 = f3(never, fo, fx); // "def"
|
||||
// Repro from #21112
|
||||
|
||||
declare function foo<T>(a: ReadonlyArray<T>): T;
|
||||
>foo : <T>(a: ReadonlyArray<T>) => T
|
||||
>a : ReadonlyArray<T>
|
||||
>foo : <T>(a: readonly T[]) => T
|
||||
>a : readonly T[]
|
||||
|
||||
let x = foo([]); // never
|
||||
>x : never
|
||||
>foo([]) : never
|
||||
>foo : <T>(a: ReadonlyArray<T>) => T
|
||||
>foo : <T>(a: readonly T[]) => T
|
||||
>[] : never[]
|
||||
|
||||
// Modified repros from #26127
|
||||
|
||||
@@ -25,10 +25,9 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,47): error TS2313: Type parameter 'V' has a circular constraint.
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,32): error TS2313: Type parameter 'T' has a circular constraint.
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,45): error TS2313: Type parameter 'V' has a circular constraint.
|
||||
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(23,24): error TS2313: Type parameter 'S' has a circular constraint.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (28 errors) ====
|
||||
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (27 errors) ====
|
||||
class C<U extends T, T extends U> { }
|
||||
~
|
||||
!!! error TS2313: Type parameter 'U' has a circular constraint.
|
||||
@@ -106,6 +105,4 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
|
||||
|
||||
type Foo<T> = [T] extends [number] ? {} : {};
|
||||
function foo<S extends Foo<S>>() {}
|
||||
~~~~~~
|
||||
!!! error TS2313: Type parameter 'S' has a circular constraint.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user