-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert
@babel/template
from Flow to TS
Co-authored-by: Bogdan Savluk <savluk.bogdan@gmail.com>
- Loading branch information
1 parent
5b69956
commit c90459c
Showing
10 changed files
with
173 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
declare module "@babel/template" { | ||
declare type PublicOpts = { | ||
placeholderWhitelist?: ?Set<string>, | ||
placeholderPattern?: ?(RegExp | false), | ||
preserveComments?: ?boolean, | ||
syntacticPlaceholders?: ?boolean, | ||
}; | ||
|
||
declare type PublicReplacements = { [string]: mixed } | Array<mixed>; | ||
|
||
declare type TemplateBuilder<T> = { | ||
ast: { | ||
(tpl: string, opts: ?PublicOpts): T, | ||
(tpl: Array<string>, ...args: Array<mixed>): T, | ||
}, | ||
(opts: PublicOpts): TemplateBuilder<T>, | ||
(tpl: string, opts: ?PublicOpts): (?PublicReplacements) => T, | ||
(tpl: Array<string>, ...args: Array<mixed>): (?PublicReplacements) => T, | ||
}; | ||
|
||
declare type Smart = TemplateBuilder< | ||
Array<BabelNodeStatement> | BabelNodeStatement | ||
>; | ||
declare type Statement = TemplateBuilder<BabelNodeStatement>; | ||
declare type Statements = TemplateBuilder<Array<BabelNodeStatement>>; | ||
declare type Expression = TemplateBuilder<BabelNodeExpression>; | ||
declare type Program = TemplateBuilder<BabelNodeProgram>; | ||
|
||
declare export default Smart & { | ||
smart: Smart, | ||
statement: Statement, | ||
statements: Statements, | ||
expression: Expression, | ||
program: Program, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as formatters from "./formatters"; | ||
import createTemplateBuilder from "./builder"; | ||
import type * as t from "@babel/types"; | ||
//const a: string = 2; | ||
export const smart = createTemplateBuilder<t.Statement | t.Statement[]>( | ||
formatters.smart, | ||
); | ||
export const statement = createTemplateBuilder<t.Statement>( | ||
formatters.statement, | ||
); | ||
export const statements = createTemplateBuilder<t.Statement[]>( | ||
formatters.statements, | ||
); | ||
export const expression = createTemplateBuilder<t.Expression>( | ||
formatters.expression, | ||
); | ||
export const program = createTemplateBuilder<t.Program>(formatters.program); | ||
|
||
type DefaultTemplateBuilder = typeof smart & { | ||
smart: typeof smart; | ||
statement: typeof statement; | ||
statements: typeof statements; | ||
expression: typeof expression; | ||
program: typeof program; | ||
ast: typeof smart.ast; | ||
}; | ||
|
||
export default Object.assign(smart.bind(undefined) as DefaultTemplateBuilder, { | ||
smart, | ||
statement, | ||
statements, | ||
expression, | ||
program, | ||
ast: smart.ast, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.