Skip to content

Commit 4651a7b

Browse files
Merge remote-tracking branch 'origin/main' into release-4.5
2 parents 39e9bc1 + 612c92d commit 4651a7b

File tree

38 files changed

+2002
-149
lines changed

38 files changed

+2002
-149
lines changed

package-lock.json

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

src/compiler/checker.ts

Lines changed: 163 additions & 129 deletions
Large diffs are not rendered by default.

src/compiler/moduleSpecifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ namespace ts.moduleSpecifiers {
619619
const nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);
620620
const packageName = getPackageNameFromTypesPackageName(nodeModulesDirectoryName);
621621
// For classic resolution, only allow importing from node_modules/@types, not other node_modules
622-
return getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs && packageName === nodeModulesDirectoryName ? undefined : packageName;
622+
return getEmitModuleResolutionKind(options) === ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;
623623

624624
function tryDirectoryWithPackageJson(packageRootIndex: number) {
625625
const packageRootPath = path.substring(0, packageRootIndex);

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7415,4 +7415,8 @@ namespace ts {
74157415
const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
74167416
return !!declaration && (isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
74177417
}
7418+
7419+
export function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction {
7420+
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
7421+
}
74187422
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [assertionTypePredicates2.js]
2+
/**
3+
* @typedef {{ x: number }} A
4+
*/
5+
6+
/**
7+
* @typedef { A & { y: number } } B
8+
*/
9+
10+
/**
11+
* @param {A} a
12+
* @returns { asserts a is B }
13+
*/
14+
const foo = (a) => {
15+
if (/** @type { B } */ (a).y !== 0) throw TypeError();
16+
return undefined;
17+
};
18+
19+
export const main = () => {
20+
/** @type { A } */
21+
const a = { x: 1 };
22+
foo(a);
23+
};
24+
25+
26+
//// [assertionTypePredicates2.js]
27+
"use strict";
28+
/**
29+
* @typedef {{ x: number }} A
30+
*/
31+
exports.__esModule = true;
32+
exports.main = void 0;
33+
/**
34+
* @typedef { A & { y: number } } B
35+
*/
36+
/**
37+
* @param {A} a
38+
* @returns { asserts a is B }
39+
*/
40+
var foo = function (a) {
41+
if ( /** @type { B } */(a).y !== 0)
42+
throw TypeError();
43+
return undefined;
44+
};
45+
var main = function () {
46+
/** @type { A } */
47+
var a = { x: 1 };
48+
foo(a);
49+
};
50+
exports.main = main;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/conformance/controlFlow/assertionTypePredicates2.js ===
2+
/**
3+
* @typedef {{ x: number }} A
4+
*/
5+
6+
/**
7+
* @typedef { A & { y: number } } B
8+
*/
9+
10+
/**
11+
* @param {A} a
12+
* @returns { asserts a is B }
13+
*/
14+
const foo = (a) => {
15+
>foo : Symbol(foo, Decl(assertionTypePredicates2.js, 12, 5))
16+
>a : Symbol(a, Decl(assertionTypePredicates2.js, 12, 13))
17+
18+
if (/** @type { B } */ (a).y !== 0) throw TypeError();
19+
>(a).y : Symbol(y, Decl(assertionTypePredicates2.js, 5, 19))
20+
>a : Symbol(a, Decl(assertionTypePredicates2.js, 12, 13))
21+
>y : Symbol(y, Decl(assertionTypePredicates2.js, 5, 19))
22+
>TypeError : Symbol(TypeError, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
23+
24+
return undefined;
25+
>undefined : Symbol(undefined)
26+
27+
};
28+
29+
export const main = () => {
30+
>main : Symbol(main, Decl(assertionTypePredicates2.js, 17, 12))
31+
32+
/** @type { A } */
33+
const a = { x: 1 };
34+
>a : Symbol(a, Decl(assertionTypePredicates2.js, 19, 9))
35+
>x : Symbol(x, Decl(assertionTypePredicates2.js, 19, 15))
36+
37+
foo(a);
38+
>foo : Symbol(foo, Decl(assertionTypePredicates2.js, 12, 5))
39+
>a : Symbol(a, Decl(assertionTypePredicates2.js, 19, 9))
40+
41+
};
42+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/conformance/controlFlow/assertionTypePredicates2.js ===
2+
/**
3+
* @typedef {{ x: number }} A
4+
*/
5+
6+
/**
7+
* @typedef { A & { y: number } } B
8+
*/
9+
10+
/**
11+
* @param {A} a
12+
* @returns { asserts a is B }
13+
*/
14+
const foo = (a) => {
15+
>foo : (a: A) => asserts a is B
16+
>(a) => { if (/** @type { B } */ (a).y !== 0) throw TypeError(); return undefined;} : (a: A) => asserts a is B
17+
>a : A
18+
19+
if (/** @type { B } */ (a).y !== 0) throw TypeError();
20+
>(a).y !== 0 : boolean
21+
>(a).y : number
22+
>(a) : B
23+
>a : A
24+
>y : number
25+
>0 : 0
26+
>TypeError() : TypeError
27+
>TypeError : TypeErrorConstructor
28+
29+
return undefined;
30+
>undefined : undefined
31+
32+
};
33+
34+
export const main = () => {
35+
>main : () => void
36+
>() => { /** @type { A } */ const a = { x: 1 }; foo(a);} : () => void
37+
38+
/** @type { A } */
39+
const a = { x: 1 };
40+
>a : A
41+
>{ x: 1 } : { x: number; }
42+
>x : number
43+
>1 : 1
44+
45+
foo(a);
46+
>foo(a) : void
47+
>foo : (a: A) => asserts a is B
48+
>a : A
49+
50+
};
51+

0 commit comments

Comments
 (0)