Skip to content

Add prettier user test and fix associated crash #23715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
path = tests/cases/user/axios-src/axios-src
url = https://github.com/axios/axios.git
ignore = all
[submodule "tests/cases/user/prettier/prettier"]
path = tests/cases/user/prettier/prettier
url = https://github.com/prettier/prettier.git
ignore = all
8 changes: 7 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,13 @@ namespace ts {

export function getJSDocHost(node: JSDocTag): HasJSDoc {
while (node.parent.kind === SyntaxKind.JSDocTypeLiteral) {
node = node.parent.parent.parent as JSDocParameterTag;
if (node.parent.parent.kind === SyntaxKind.JSDocTypedefTag) {
node = node.parent.parent as JSDocTypedefTag;
}
else {
// node.parent.parent is a type expression, child of a parameter type
node = node.parent.parent.parent as JSDocParameterTag;
}
}
Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment);
return node.parent!.parent!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js(21,1): error TS2322: Type 'false' is not assignable to type 'number'.
tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js(26,15): error TS2304: Cannot find name 'T'.


==== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js (1 errors) ====
==== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js (2 errors) ====
/**
* @template {T}
* @param {T} t
Expand All @@ -25,4 +26,14 @@ tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js(21,1): error T
z.u = false
~~~
!!! error TS2322: Type 'false' is not assignable to type 'number'.

// lookup in typedef should not crash the compiler, even when the type is unknown
/**
* @typedef {Object} A
* @property {T} value
~
!!! error TS2304: Cannot find name 'T'.
*/
/** @type {A} */
const options = { value: null };

Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ z.u = false
>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3))
>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))

// lookup in typedef should not crash the compiler, even when the type is unknown
/**
* @typedef {Object} A
* @property {T} value
*/
/** @type {A} */
const options = { value: null };
>options : Symbol(options, Decl(templateTagWithNestedTypeLiteral.js, 28, 5))
>value : Symbol(value, Decl(templateTagWithNestedTypeLiteral.js, 28, 17))

12 changes: 12 additions & 0 deletions tests/baselines/reference/jsdocTemplateConstructorFunction2.types
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ z.u = false
>u : number
>false : false

// lookup in typedef should not crash the compiler, even when the type is unknown
/**
* @typedef {Object} A
* @property {T} value
*/
/** @type {A} */
const options = { value: null };
>options : { value: any; }
>{ value: null } : { value: null; }
>value : null
>null : null

92 changes: 92 additions & 0 deletions tests/baselines/reference/user/prettier.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Exit Code: 1
Standard output:
index.js(3,25): error TS2307: Cannot find module './package.json'.
index.js(138,21): error TS2532: Object is possibly 'undefined'.
src/cli/util.js(262,64): error TS2339: Property 'length' does not exist on type 'Ignore'.
src/cli/util.js(335,52): error TS2339: Property 'length' does not exist on type 'Ignore'.
src/cli/util.js(396,46): error TS2345: Argument of type 'null' is not assignable to parameter of type 'number | undefined'.
src/cli/util.js(403,39): error TS2339: Property 'grey' does not exist on type 'typeof import("/home/nathansa/ts/node_modules/chalk/types/index")'.
src/common/parser-create-error.js(8,9): error TS2339: Property 'loc' does not exist on type 'SyntaxError'.
src/config/resolve-config.js(75,32): error TS2345: Argument of type '{ sync: false; }' is not assignable to parameter of type '{ cache: boolean; sync: boolean; }'.
Property 'cache' is missing in type '{ sync: false; }'.
src/config/resolve-config.js(82,32): error TS2345: Argument of type '{ sync: true; }' is not assignable to parameter of type '{ cache: boolean; sync: boolean; }'.
Property 'cache' is missing in type '{ sync: true; }'.
src/doc/doc-printer.js(213,17): error TS2532: Object is possibly 'undefined'.
src/doc/doc-printer.js(214,18): error TS2532: Object is possibly 'undefined'.
src/doc/doc-printer.js(215,17): error TS2532: Object is possibly 'undefined'.
src/language-css/clean.js(3,30): error TS2307: Cannot find module 'html-tag-names'.
src/language-css/parser-postcss.js(78,32): error TS2345: Argument of type '{ [x: string]: any; groups: never[]; type: string; }' is not assignable to parameter of type 'never'.
src/language-css/parser-postcss.js(88,30): error TS2345: Argument of type '{ [x: string]: any; open: null; close: null; groups: never[]; type: string; }' is not assignable to parameter of type 'never'.
src/language-css/parser-postcss.js(93,30): error TS2345: Argument of type '{ [x: string]: any; groups: never[]; type: string; }' is not assignable to parameter of type 'never'.
src/language-css/parser-postcss.js(100,30): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
src/language-css/parser-postcss.js(104,28): error TS2345: Argument of type '{ [x: string]: any; groups: never[]; type: string; }' is not assignable to parameter of type 'never'.
src/language-css/parser-postcss.js(407,32): error TS2531: Object is possibly 'null'.
src/language-css/printer-postcss.js(3,30): error TS2307: Cannot find module 'html-tag-names'.
src/language-handlebars/parser-glimmer.js(27,26): error TS2345: Argument of type '{ plugins: { ast: (() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): voi...' is not assignable to parameter of type 'PreprocessOptions | undefined'.
Type '{ plugins: { ast: (() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): voi...' is not assignable to type 'PreprocessOptions'.
Types of property 'plugins' are incompatible.
Type '{ ast: (() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementN...' is not assignable to type '{ ast?: ASTPluginBuilder[] | undefined; } | undefined'.
Type '{ ast: (() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementN...' is not assignable to type '{ ast?: ASTPluginBuilder[] | undefined; }'.
Types of property 'ast' are incompatible.
Type '(() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementNode(nod...' is not assignable to type 'ASTPluginBuilder[] | undefined'.
Type '(() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementNode(nod...' is not assignable to type 'ASTPluginBuilder[]'.
Type '() => { [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementNode(node...' is not assignable to type 'ASTPluginBuilder'.
Type '{ [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementNode(node: any)...' is not assignable to type 'ASTPlugin'.
Property 'name' is missing in type '{ [x: string]: any; visitor: { [x: string]: any; Program(node: any): void; ElementNode(node: any)...'.
src/language-handlebars/printer-glimmer.js(270,7): error TS2554: Expected 0-1 arguments, but got 2.
src/language-js/printer-estree.js(99,9): error TS2322: Type '{ [x: string]: any; type: string; }' is not assignable to type '{ [x: string]: any; type: string; parts: any; }'.
Property 'parts' is missing in type '{ [x: string]: any; type: string; }'.
src/language-js/printer-estree.js(302,9): error TS2345: Argument of type '{ [x: string]: any; type: string; parts: any; } | { [x: string]: any; type: string; contents: any...' is not assignable to parameter of type 'ConcatArray<never>'.
Type '{ [x: string]: any; type: string; parts: any; }' is not assignable to type 'ConcatArray<never>'.
Property 'length' is missing in type '{ [x: string]: any; type: string; parts: any; }'.
src/language-js/printer-estree.js(1224,28): error TS2345: Argument of type '{ [x: string]: any; type: string; parts: any; }' is not assignable to parameter of type 'string | ConcatArray<string>'.
Type '{ [x: string]: any; type: string; parts: any; }' is not assignable to type 'ConcatArray<string>'.
Property 'length' is missing in type '{ [x: string]: any; type: string; parts: any; }'.
src/language-js/printer-estree.js(1601,20): error TS2345: Argument of type '" "' is not assignable to parameter of type '{ [x: string]: any; type: string; contents: any; break: boolean; expandedStates: any; }'.
src/language-js/printer-estree.js(1603,20): error TS2345: Argument of type '{ [x: string]: any; type: string; parts: any; }' is not assignable to parameter of type '{ [x: string]: any; type: string; contents: any; break: boolean; expandedStates: any; }'.
Property 'contents' is missing in type '{ [x: string]: any; type: string; parts: any; }'.
src/language-js/printer-estree.js(1605,18): error TS2345: Argument of type '"while ("' is not assignable to parameter of type '{ [x: string]: any; type: string; contents: any; break: boolean; expandedStates: any; }'.
src/language-js/printer-estree.js(1614,9): error TS2345: Argument of type '")"' is not assignable to parameter of type '{ [x: string]: any; type: string; contents: any; break: boolean; expandedStates: any; }'.
src/language-js/printer-estree.js(3293,23): error TS2532: Object is possibly 'undefined'.
src/language-js/printer-estree.js(3294,24): error TS2532: Object is possibly 'undefined'.
src/language-js/printer-estree.js(3647,5): error TS2345: Argument of type '"" | { [x: string]: any; type: string; parts: any; } | { [x: string]: any; type: string; contents...' is not assignable to parameter of type 'string'.
Type '{ [x: string]: any; type: string; parts: any; }' is not assignable to type 'string'.
src/language-js/printer-estree.js(3651,16): error TS2345: Argument of type '{ [x: string]: any; type: string; parts: any; }' is not assignable to parameter of type 'string'.
src/language-js/printer-estree.js(3693,9): error TS2345: Argument of type '{ [x: string]: any; type: string; parts: any; }' is not assignable to parameter of type 'string'.
src/language-js/printer-estree.js(3995,14): error TS2554: Expected 0-2 arguments, but got 3.
src/language-js/printer-estree.js(5034,9): error TS2554: Expected 0-1 arguments, but got 2.
src/language-js/printer-estree.js(5070,7): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type '((childPath: any) => any) | ConcatArray<(childPath: any) => any>'.
Type '(string | number)[]' is not assignable to type 'ConcatArray<(childPath: any) => any>'.
Types of property 'slice' are incompatible.
Type '(start?: number | undefined, end?: number | undefined) => (string | number)[]' is not assignable to type '(start?: number | undefined, end?: number | undefined) => ((childPath: any) => any)[]'.
Type '(string | number)[]' is not assignable to type '((childPath: any) => any)[]'.
Type 'string | number' is not assignable to type '(childPath: any) => any'.
Type 'string' is not assignable to type '(childPath: any) => any'.
src/language-markdown/printer-markdown.js(258,18): error TS2532: Object is possibly 'undefined'.
src/language-markdown/printer-markdown.js(259,17): error TS2532: Object is possibly 'undefined'.
src/language-markdown/printer-markdown.js(283,14): error TS2532: Object is possibly 'undefined'.
src/language-vue/parser-vue.js(54,23): error TS2345: Argument of type '(m: string, g: any) => void' is not assignable to parameter of type '(substring: string, ...args: any[]) => string'.
Type 'void' is not assignable to type 'string'.
src/language-vue/parser-vue.js(180,34): error TS2339: Property 'toLowerCase' does not exist on type 'never'.
src/language-vue/parser-vue.js(244,26): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
src/language-vue/parser-vue.js(393,25): error TS2345: Argument of type '{ [x: string]: any; tag: any; attrs: any; unary: any; start: any; children: never[]; }' is not assignable to parameter of type 'never'.
src/language-vue/parser-vue.js(398,23): error TS2345: Argument of type '{ [x: string]: any; tag: any; attrs: any; unary: any; start: any; children: never[]; }' is not assignable to parameter of type '{ [x: string]: any; tag: string; attrs: never[]; unary: boolean; start: number; contentStart: num...'.
Property 'contentStart' is missing in type '{ [x: string]: any; tag: any; attrs: any; unary: any; start: any; children: never[]; }'.
src/language-vue/parser-vue.js(399,9): error TS2322: Type '{ [x: string]: any; tag: any; attrs: any; unary: any; start: any; children: never[]; }' is not assignable to type '{ [x: string]: any; tag: string; attrs: never[]; unary: boolean; start: number; contentStart: num...'.
src/main/core-options.js(51,43): error TS1005: '}' expected.
src/main/core-options.js(63,5): error TS2322: Type '{ cursorOffset: { since: string; category: string; type: "int"; default: number; range: { start: ...' is not assignable to type '{ [name: string]: { since: string; category: string; type: "boolean" | "path" | "int" | "choice";...'.
Property 'cursorOffset' is incompatible with index signature.
Type '{ since: string; category: string; type: "int"; default: number; range: { start: number; end: num...' is not assignable to type '{ since: string; category: string; type: "boolean" | "path" | "int" | "choice"; array: boolean; d...'.
Object literal may only specify known properties, and 'cliCategory' does not exist in type '{ since: string; category: string; type: "boolean" | "path" | "int" | "choice"; array: boolean; d...'.
src/main/parser.js(61,9): error TS2345: Argument of type 'PropertyDescriptor | undefined' is not assignable to parameter of type 'PropertyDescriptor & ThisType<any>'.
Type 'undefined' is not assignable to type 'PropertyDescriptor & ThisType<any>'.
Type 'undefined' is not assignable to type 'PropertyDescriptor'.
src/main/support.js(5,32): error TS2307: Cannot find module '../../package.json'.
src/main/support.js(36,24): error TS2339: Property 'name' does not exist on type 'never'.
src/main/support.js(36,35): error TS2339: Property 'name' does not exist on type 'never'.
src/main/support.js(36,48): error TS2339: Property 'name' does not exist on type 'never'.
src/main/support.js(36,57): error TS2339: Property 'name' does not exist on type 'never'.



Standard error:
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ Zet.prototype.add = function(v, o) {
var z = new Zet(1)
z.t = 2
z.u = false

// lookup in typedef should not crash the compiler, even when the type is unknown
/**
* @typedef {Object} A
* @property {T} value
*/
/** @type {A} */
const options = { value: null };
1 change: 1 addition & 0 deletions tests/cases/user/prettier/prettier
Submodule prettier added at 67f1c4
3 changes: 3 additions & 0 deletions tests/cases/user/prettier/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"types": ["node"]
}
17 changes: 17 additions & 0 deletions tests/cases/user/prettier/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"noImplicitAny": false,
"noImplicitThis": false,
"maxNodeModuleJsDepth": 0,
"strict": true,
"noEmit": true,
"allowJs": true,
"checkJs": true,
"types": ["node"],
"lib": ["esnext", "dom"],
"target": "esnext",
"module": "commonjs",
"pretty": false,
},
"include": ["prettier/src"]
}