diff --git a/types/buble/buble-tests.ts b/types/buble/buble-tests.ts new file mode 100644 index 0000000000..e786ee6854 --- /dev/null +++ b/types/buble/buble-tests.ts @@ -0,0 +1,77 @@ +import * as buble from 'buble'; + +const input = 'const answer = () => 42;'; + +// Simple transform +(() => { + const output = buble.transform(input); + + console.log(output.code); + console.log(output.map.toString()); + console.log(output.map.toUrl); +})(); + +// Transform for Chrome & Firefox +(() => { + const output = buble.transform(input, { + target: { + chrome: 71, + firefox: 64, + }, + }); +})(); + +// Transform with sourcemaps support +(() => { + const output = buble.transform(input, { + source: 'input.js', + file: 'output.js', + includeContent: true, + }); +})(); + +// Transform for Preact +(() => { + const output = buble.transform(input, { + jsx: 'h' + }); +})(); + +// Transform with Object assign/spread support +(() => { + let output = buble.transform(input, { + objectAssign: true, + }); + output = buble.transform(input, { + objectAssign: 'MyCustomObjectAssign', + }); +})(); + +// Transform with every transforms +(() => { + const output = buble.transform(input, { + transforms: { + arrow: true, + classes: false, + collections: true, + computedProperty: false, + conciseMethodProperty: true, + constLoop: false, + dangerousForOf: true, + dangerousTaggedTemplateString: false, + defaultParameter: true, + destructuring: false, + forOf: true, + generator: false, + letConst: true, + modules: false, + numericLiteral: true, + parameterDestructuring: false, + reservedProperties: true, + spreadRest: false, + stickyRegExp: true, + templateString: false, + unicodeRegExp: true, + } + }); +})(); diff --git a/types/buble/index.d.ts b/types/buble/index.d.ts new file mode 100644 index 0000000000..c222d08e87 --- /dev/null +++ b/types/buble/index.d.ts @@ -0,0 +1,65 @@ +// Type definitions for buble 0.19 +// Project: https://github.com/Rich-Harris/buble#README +// Definitions by: Kocal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface TransformOptions { + // source: https://github.com/Rich-Harris/buble/blob/master/src/support.js + target?: { + chrome?: 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71; + firefox?: 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64; + safari?: 8 | 9 | 10 | 10.1 | 11 | 11.1 | 12; + ie?: 8 | 9 | 10 | 11; + edge?: 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19; + node?: 0.10 | 0.12 | 4 | 5 | 6 | 8 | 8.3 | 8.7 | 8.10; + }; + + // used for sourcemaps + source?: string; // input + file?: string; // output + includeContent?: boolean; + + // custom JSX pragma (https://buble.surge.sh/guide/#jsx) + jsx?: string; // default: 'React.createElement' + + // custom `Object.assign` (https://buble.surge.sh/guide/#object-spread-and-rest) + objectAssign?: string | boolean; + + // transforms + transforms?: { + arrow?: boolean; + classes?: boolean; + collections?: boolean; + computedProperty?: boolean; + conciseMethodProperty?: boolean; + constLoop?: boolean; + dangerousForOf?: boolean; + dangerousTaggedTemplateString?: boolean; + defaultParameter?: boolean; + destructuring?: boolean; + forOf?: boolean; + generator?: boolean; + letConst?: boolean; + modules?: boolean; + numericLiteral?: boolean; + parameterDestructuring?: boolean; + reservedProperties?: boolean; + spreadRest?: boolean; + stickyRegExp?: boolean; + templateString?: boolean; + unicodeRegExp?: boolean; + }; + + // others + namedFunctionExpressions?: boolean; +} + +export interface TransformOutput { + code: string; + map: { + toString(): string; + toUrl(): string; + }; +} + +export function transform(content: string, options?: TransformOptions): TransformOutput; diff --git a/types/buble/tsconfig.json b/types/buble/tsconfig.json new file mode 100644 index 0000000000..0196ebd845 --- /dev/null +++ b/types/buble/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "buble-tests.ts" + ] +} diff --git a/types/buble/tslint.json b/types/buble/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/buble/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }