Skip to content

Commit c60d510

Browse files
committed
Address reviews, consolidate code
1 parent fbc2707 commit c60d510

39 files changed

+6386
-3044
lines changed
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
export class Constructor {
2-
constructor(public readonly property: number) {}
1+
// export class Constructor {
2+
// constructor(public readonly property: number) {}
3+
// }
4+
5+
namespace Yay {
6+
export class SuperConstructor {
7+
constructor(public readonly property: number) {
8+
}
9+
}
10+
11+
export namespace Woo {
12+
export class MyClass {
13+
constructor() {}
14+
}
15+
}
16+
}
17+
18+
export class SuperConstructor2 {
19+
constructor(public readonly property: number) {
20+
}
21+
}
22+
23+
export function useConstructor(): Yay.SuperConstructor {
24+
return new Yay.SuperConstructor(10)
25+
}
26+
27+
export function useConstructor2(): SuperConstructor2 {
28+
return new SuperConstructor2(10)
329
}
430

5-
export function useConstructor(): Constructor {
6-
return new Constructor(Constructor.name.length)
31+
export function useConstructor3(): Yay.Woo.MyClass {
32+
return new Yay.Woo.MyClass()
733
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function a(): string {
2+
// definition @example/a HEAD src/`a.ts`/
3+
//documentation ```ts\nmodule "a.ts"\n```
4+
// ^ definition @example/a HEAD src/`a.ts`/a().
5+
// documentation ```ts\nfunction a(): string\n```
6+
return ''
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function a(): string {
2+
// definition @example/a 1.0.0 src/`index.ts`/
3+
//documentation ```ts\nmodule "index.ts"\n```
4+
// ^ definition @example/a 1.0.0 src/`index.ts`/a().
5+
// documentation ```ts\nfunction a(): string\n```
6+
return ''
7+
}
8+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { a } from '@example/a/src'
2+
// definition @example/b 1.0.0 src/`b.ts`/
3+
//documentation ```ts\nmodule "b.ts"\n```
4+
// ^ reference @example/a 1.0.0 src/`index.ts`/a().
5+
// ^^^^^^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/
6+
7+
export function b() {
8+
// ^ definition @example/b 1.0.0 src/`b.ts`/b().
9+
// documentation ```ts\nfunction b(): string\n```
10+
return a()
11+
// ^ reference @example/a 1.0.0 src/`index.ts`/a().
12+
}
13+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function a(): string {
2+
// definition @example/a 1.0.0 src/`a.ts`/
3+
//documentation ```ts\nmodule "a.ts"\n```
4+
// ^ definition @example/a 1.0.0 src/`a.ts`/a().
5+
// documentation ```ts\nfunction a(): string\n```
6+
return ''
7+
}
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { a } from '@example/a'
2+
// definition @example/b 1.0.0 src/`b.ts`/
3+
//documentation ```ts\nmodule "b.ts"\n```
4+
// ^ reference local 0
5+
6+
export function b() {
7+
// ^ definition @example/b 1.0.0 src/`b.ts`/b().
8+
// documentation ```ts\nfunction b(): any\n```
9+
return a()
10+
// ^ reference local 0
11+
}
12+

snapshots/output/pure-js/src/main.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
function fib(n) {
2+
// definition pure-js 1.0.0 src/`main.js`/
3+
//documentation ```ts\nmodule "main.js"\n```
4+
// ^^^ definition pure-js 1.0.0 src/`main.js`/fib().
5+
// documentation ```ts\nfunction fib(n: any): any\n```
6+
// ^ definition pure-js 1.0.0 src/`main.js`/fib().(n)
7+
// documentation ```ts\n(parameter) n: any\n```
8+
if (n <= 1) {
9+
// ^ reference pure-js 1.0.0 src/`main.js`/fib().(n)
10+
return 0
11+
}
12+
return fib(n - 1) + fib(n - 2)
13+
// ^^^ reference pure-js 1.0.0 src/`main.js`/fib().
14+
// ^ reference pure-js 1.0.0 src/`main.js`/fib().(n)
15+
// ^^^ reference pure-js 1.0.0 src/`main.js`/fib().
16+
// ^ reference pure-js 1.0.0 src/`main.js`/fib().(n)
17+
}
18+
19+
function print_fib(a) {
20+
// ^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/print_fib().
21+
// documentation ```ts\nfunction print_fib(a: any): void\n```
22+
// ^ definition pure-js 1.0.0 src/`main.js`/print_fib().(a)
23+
// documentation ```ts\n(parameter) a: any\n```
24+
console.log(fib(a))
25+
// ^^^^^^^ reference typescript 4.8.4 lib/`lib.dom.d.ts`/console.
26+
// ^^^^^^^ reference @types/node 17.0.14 `globals.d.ts`/console.
27+
// ^^^^^^^ reference @types/node 17.0.14 `console.d.ts`/`'node:console'`/global/console/
28+
// ^^^^^^^ reference @types/node 17.0.14 `console.d.ts`/`'node:console'`/global/console.
29+
// ^^^ reference typescript 4.8.4 lib/`lib.dom.d.ts`/Console#log().
30+
// ^^^ reference @types/node 17.0.14 `console.d.ts`/`'node:console'`/global/Console#log().
31+
// ^^^ reference pure-js 1.0.0 src/`main.js`/fib().
32+
// ^ reference pure-js 1.0.0 src/`main.js`/print_fib().(a)
33+
}
34+
35+
var y = 'Hello'
36+
// ^ definition pure-js 1.0.0 src/`main.js`/y.
37+
// documentation ```ts\nvar y: string\n```
38+
function capture() {
39+
// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/capture().
40+
// documentation ```ts\nfunction capture(): string\n```
41+
return y
42+
// ^ reference pure-js 1.0.0 src/`main.js`/y.
43+
}
44+
const capture_lambda = () => {
45+
// ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/capture_lambda.
46+
// documentation ```ts\nvar capture_lambda: () => string\n```
47+
return y
48+
// ^ reference pure-js 1.0.0 src/`main.js`/y.
49+
}
50+
51+
for (var i = 0; i <= 10; i++) {}
52+
// ^ definition local 2
53+
// documentation ```ts\nvar i: number\n```
54+
// ^ reference local 2
55+
// ^ reference local 2
56+
57+
for (const x of [1, 2, 3]) {
58+
// ^ definition local 5
59+
// documentation ```ts\nvar x: number\n```
60+
}
61+
62+
var a = 0
63+
// ^ definition pure-js 1.0.0 src/`main.js`/a.
64+
// documentation ```ts\nvar a: number\n```
65+
var a = 1
66+
// ^ definition pure-js 1.0.0 src/`main.js`/a.
67+
// documentation ```ts\nvar a: number\n```
68+
print_fib(a)
69+
//^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
70+
// ^ reference pure-js 1.0.0 src/`main.js`/a.
71+
72+
function forever() {
73+
// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/forever().
74+
// documentation ```ts\nfunction forever(): any\n```
75+
return forever()
76+
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
77+
}
78+
79+
function use_before_def() {
80+
// ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/use_before_def().
81+
// documentation ```ts\nfunction use_before_def(): void\n```
82+
print_fib(n)
83+
// ^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
84+
// ^ reference local 8
85+
var n = 10
86+
// ^ definition local 8
87+
// documentation ```ts\nvar n: number\n```
88+
89+
if (forever()) {
90+
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
91+
var m = 10
92+
// ^ definition local 11
93+
// documentation ```ts\nvar m: number\n```
94+
}
95+
print_fib(m)
96+
// ^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
97+
// ^ reference local 11
98+
}
99+
100+
function var_function_scope() {
101+
// ^^^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/var_function_scope().
102+
// documentation ```ts\nfunction var_function_scope(): void\n```
103+
var k = 0
104+
// ^ definition local 14
105+
// documentation ```ts\nvar k: number\n```
106+
if (forever()) {
107+
// ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever().
108+
var k = 1
109+
// ^ definition local 17
110+
// documentation ```ts\nvar k: number\n```
111+
}
112+
print_fib(k)
113+
// ^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib().
114+
// ^ reference local 14
115+
// ^ reference local 17
116+
}
117+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react'
2+
// definition react-example 1.0.0 src/`LoaderInput.tsx`/
3+
//documentation ```ts\nmodule "LoaderInput.tsx"\n```
4+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/
6+
7+
/** Takes loading prop, input component as child */
8+
interface Props {
9+
// ^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#
10+
// documentation ```ts\ninterface Props\n```
11+
// documentation Takes loading prop, input component as child
12+
loading: boolean
13+
// ^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
14+
// documentation ```ts\n(property) loading: boolean\n```
15+
children: React.ReactNode
16+
// ^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
17+
// documentation ```ts\n(property) children: ReactNode\n```
18+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
19+
// ^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/ReactNode#
20+
}
21+
22+
export const LoaderInput: React.FunctionComponent<Props> = ({
23+
// ^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
24+
// documentation ```ts\nvar LoaderInput: FunctionComponent<Props>\n```
25+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
26+
// ^^^^^^^^^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/FunctionComponent#
27+
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
28+
loading,
29+
// ^^^^^^^ definition local 3
30+
// documentation ```ts\n(parameter) loading: boolean\n```
31+
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
32+
children,
33+
// ^^^^^^^^ definition local 4
34+
// documentation ```ts\n(parameter) children: ReactNode\n```
35+
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
36+
// ^^^^^^^^ reference local 7
37+
}) => (
38+
<div className="hello">
39+
// ^^^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#div.
40+
// ^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/HTMLAttributes#className.
41+
{children}
42+
// ^^^^^^^^ reference local 4
43+
{loading && <p>spinner</p>}
44+
// ^^^^^^^ reference local 3
45+
// ^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#p.
46+
// ^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#p.
47+
</div>
48+
// ^^^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#div.
49+
)
50+
51+
export const LoaderInput2: React.FunctionComponent<Props> = props => {
52+
// ^^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput2.
53+
// documentation ```ts\nvar LoaderInput2: FunctionComponent<Props>\n```
54+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
55+
// ^^^^^^^^^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/FunctionComponent#
56+
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
57+
// ^^^^^ definition local 9
58+
// documentation ```ts\n(parameter) props: PropsWithChildren<Props>\n```
59+
return <LoaderInput loading={true} key="key" children={props.children} />
60+
// ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
61+
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
62+
// ^^^ reference local 13
63+
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
64+
// ^^^^^ reference local 9
65+
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
66+
// ^^^^^^^^ reference local 7
67+
}
68+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
// definition react-example 1.0.0 src/`MyTSXElement.tsx`/
3+
//documentation ```ts\nmodule "MyTSXElement.tsx"\n```
4+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/
6+
7+
export interface MyProps {}
8+
// ^^^^^^^ definition react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
9+
// documentation ```ts\ninterface MyProps\n```
10+
11+
export const MyTSXElement: React.FunctionComponent<MyProps> = ({}) => (<p></p>)
12+
// ^^^^^^^^^^^^ definition react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement.
13+
// documentation ```ts\nvar MyTSXElement: FunctionComponent<MyProps>\n```
14+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
15+
// ^^^^^^^^^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/FunctionComponent#
16+
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
17+
// ^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#p.
18+
// ^ reference @types/react 17.0.52 `index.d.ts`/global/JSX/IntrinsicElements#p.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
// definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/
3+
//documentation ```ts\nmodule "UseMyTSXElement.tsx"\n```
4+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
5+
// ^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/
6+
7+
import { MyProps, MyTSXElement } from "./MyTSXElement";
8+
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
9+
// ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement.
10+
// ^^^^^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/
11+
12+
export const _: React.FunctionComponent<MyProps> =
13+
// ^ definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/_.
14+
// documentation ```ts\nvar _: FunctionComponent<MyProps>\n```
15+
// ^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/
16+
// ^^^^^^^^^^^^^^^^^ reference @types/react 17.0.52 `index.d.ts`/React/FunctionComponent#
17+
// ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps#
18+
({}) => (<MyTSXElement></MyTSXElement>)
19+
// ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement.
20+
// ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export class ClassWithPrivate {
2+
// definition syntax 1.0.0 src/`ClassWithPrivate.ts`/
3+
//documentation ```ts\nmodule "ClassWithPrivate.ts"\n```
4+
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#
5+
// documentation ```ts\nclass ClassWithPrivate\n```
6+
#privateField
7+
// ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`.
8+
// documentation ```ts\n(property) #privateField: any\n```
9+
#privateFieldWithInitializer = 42
10+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateFieldWithInitializer`.
11+
// documentation ```ts\n(property) #privateFieldWithInitializer: number\n```
12+
13+
#privateMethod() {
14+
// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateMethod`().
15+
// documentation ```ts\n(method) #privateMethod(): any\n```
16+
this.#privateField = 'private field'
17+
// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`.
18+
return this.#privateField
19+
// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`.
20+
}
21+
22+
static #privateStaticField
23+
// ^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticField`.
24+
// documentation ```ts\n(property) #privateStaticField: any\n```
25+
static #privateStaticFieldWithInitializer = 42
26+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticFieldWithInitializer`.
27+
// documentation ```ts\n(property) #privateStaticFieldWithInitializer: number\n```
28+
29+
static #privateStaticMethod() {}
30+
// ^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticMethod`().
31+
// documentation ```ts\n(method) #privateStaticMethod(): void\n```
32+
public publicMethod(): any[] {
33+
// ^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#publicMethod().
34+
// documentation ```ts\n(method) publicMethod(): any[]\n```
35+
return [
36+
this.#privateField,
37+
// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`.
38+
this.#privateFieldWithInitializer,
39+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateFieldWithInitializer`.
40+
this.#privateMethod(),
41+
// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateMethod`().
42+
ClassWithPrivate.#privateStaticMethod(),
43+
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#
44+
// ^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticMethod`().
45+
ClassWithPrivate.#privateStaticField,
46+
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#
47+
// ^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticField`.
48+
ClassWithPrivate.#privateStaticFieldWithInitializer,
49+
// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#
50+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticFieldWithInitializer`.
51+
]
52+
}
53+
}
54+

0 commit comments

Comments
 (0)