-
Notifications
You must be signed in to change notification settings - Fork 4
rewrite components doc generator #58
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| build | ||
| lib | ||
| node_modules | ||
| /node_modules | ||
| coverage |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import * as React from 'react'; | ||
|
|
||
| export interface ColumnLayoutProps { | ||
| columns: ColumnLayoutProps.Columns; | ||
| widths: ColumnLayoutProps.Widths; | ||
| } | ||
|
|
||
| export namespace ColumnLayoutProps { | ||
| export type Columns = 1 | 2 | 3 | 4; | ||
| export type Widths = 25 | '50%' | 100 | '33%'; | ||
| } | ||
|
|
||
| export default function ColumnLayout(props: ColumnLayoutProps) { | ||
|
Check warning on line 15 in fixtures/components/complex-types/column-layout/index.tsx
|
||
| return <div></div>; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| import * as React from 'react'; | ||
| import { TableProps } from './interfaces'; | ||
|
|
||
| export { TableProps }; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new implementation is more strict, it checks that the interface is actually exported in the index file (which was our requirement all the time) |
||
|
|
||
| export default function Table<T = any>(props: TableProps<T>) { | ||
|
Check warning on line 8 in fixtures/components/complex-types/table/index.tsx
|
||
| return <table />; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| export default function Button() { | ||
| // if a function does not return JSX, we throw | ||
| return { type: 'button' }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| export interface DependencyProps { | ||
| name?: string; | ||
| variant?: DependencyProps.Variant; | ||
| } | ||
|
|
||
| // should not be included in the Main component API definition | ||
| export interface MainProps { | ||
| randomValue: string; | ||
| } | ||
|
|
||
| export namespace DependencyProps { | ||
| export type Variant = 'button' | 'link'; | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { IconProps } from '../node_modules_mock/icon'; | ||
| import { IconProps } from 'icon'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this test to more accurately represent |
||
|
|
||
| export interface ButtonProps { | ||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import ts from 'typescript'; | ||
| import pathe from 'pathe'; | ||
|
|
||
| function printDiagnostics(diagnostics: readonly ts.Diagnostic[]): void { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Official docs for API used in this file: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API |
||
| for (const diagnostic of diagnostics) { | ||
| const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); | ||
| if (diagnostic.file) { | ||
| const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!); | ||
| console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); | ||
| } else { | ||
| console.error(message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function loadTSConfig(tsconfigPath: string): ts.ParsedCommandLine { | ||
| const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); | ||
| if (configFile.error) { | ||
| throw new Error('Failed to read tsconfig.json'); | ||
| } | ||
| const config = ts.parseJsonConfigFileContent(configFile.config, ts.sys, pathe.dirname(tsconfigPath)); | ||
| if (config.errors.length > 0) { | ||
| throw new Error('Failed to parse tsconfig.json'); | ||
| } | ||
| // this prints a warning that incremental mode is not supported in programmatic API | ||
| config.options.incremental = false; | ||
| delete config.options.tsBuildInfoFile; | ||
| return config; | ||
| } | ||
|
|
||
| export function bootstrapTypescriptProject(tsconfigPath: string) { | ||
| const tsconfig = loadTSConfig(tsconfigPath); | ||
| const program = ts.createProgram(tsconfig.fileNames, tsconfig.options); | ||
|
|
||
| const diagnostics = ts.getPreEmitDiagnostics(program); | ||
| if (diagnostics.length > 0) { | ||
| printDiagnostics(diagnostics); | ||
| throw new Error('Compilation failed'); | ||
| } | ||
|
|
||
| return program; | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new test case on number-only and on mixed string+number union types.
We do not have a real use-case yet, but let's make sure it works anyway