Skip to content

Commit

Permalink
Only target es2017 with TS pass it to babel + bublé
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Nov 27, 2018
1 parent a89d6d2 commit cebff34
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 33 deletions.
45 changes: 24 additions & 21 deletions src/index.js
Expand Up @@ -359,31 +359,34 @@ function createConfig(options, entry, format, writeMeta) {
jsx: options.jsx,
},
},
tsconfigOverride: {
compilerOptions: {
target: 'es2017',
},
},
}),
!useTypescript && flow({ all: true, pretty: true }),
// Only used for async await
!useTypescript &&
babel({
exclude: 'node_modules/**',
plugins: [
'@babel/plugin-syntax-jsx',
[
'babel-plugin-transform-async-to-promises',
{ inlineHelpers: true, externalHelpers: true },
],
['@babel/plugin-proposal-class-properties', { loose: true }],
babel({
exclude: 'node_modules/**',
plugins: [
'@babel/plugin-syntax-jsx',
[
'babel-plugin-transform-async-to-promises',
{ inlineHelpers: true, externalHelpers: true },
],
}),
!useTypescript &&
buble({
exclude: 'node_modules/**',
jsx: options.jsx || 'h',
objectAssign: options.assign || 'Object.assign',
transforms: {
dangerousForOf: true,
dangerousTaggedTemplateString: true,
},
}),
['@babel/plugin-proposal-class-properties', { loose: true }],
],
}),
buble({
exclude: 'node_modules/**',
jsx: options.jsx || 'h',
objectAssign: options.assign || 'Object.assign',
transforms: {
dangerousForOf: true,
dangerousTaggedTemplateString: true,
},
}),
useNodeResolve &&
commonjs({
include: 'node_modules/**',
Expand Down
82 changes: 70 additions & 12 deletions test/__snapshots__/index.test.js.snap
Expand Up @@ -80,12 +80,12 @@ basic-ts
Build \\"basicLibTs\\" to dist:
104 B: basic-lib-ts.js.gz
76 B: basic-lib-ts.js.br
97 B: basic-lib-ts.mjs.gz
73 B: basic-lib-ts.mjs.br
180 B: basic-lib-ts.umd.js.gz
137 B: basic-lib-ts.umd.js.br"
98 B: basic-lib-ts.js.gz
67 B: basic-lib-ts.js.br
92 B: basic-lib-ts.mjs.gz
58 B: basic-lib-ts.mjs.br
176 B: basic-lib-ts.umd.js.gz
139 B: basic-lib-ts.umd.js.br"
`;

exports[`fixtures basic-tsx 1`] = `
Expand All @@ -109,12 +109,12 @@ basic-tsx
Build \\"basicLibTsx\\" to dist:
221 B: basic-lib-tsx.js.gz
179 B: basic-lib-tsx.js.br
222 B: basic-lib-tsx.mjs.gz
197 B: basic-lib-tsx.mjs.br
295 B: basic-lib-tsx.umd.js.gz
236 B: basic-lib-tsx.umd.js.br"
211 B: basic-lib-tsx.js.gz
168 B: basic-lib-tsx.js.br
212 B: basic-lib-tsx.mjs.gz
170 B: basic-lib-tsx.mjs.br
290 B: basic-lib-tsx.umd.js.gz
228 B: basic-lib-tsx.umd.js.br"
`;

exports[`fixtures basic-with-cwd 1`] = `
Expand Down Expand Up @@ -147,6 +147,35 @@ Build \\"basic\\" to dist:
208 B: basic.umd.js.br"
`;

exports[`fixtures class-decorators-ts 1`] = `
"Used script: microbundle --raw
Directory tree:
class-decorators-ts
dist
class-decorators-ts.js
class-decorators-ts.js.map
class-decorators-ts.mjs
class-decorators-ts.mjs.map
class-decorators-ts.umd.js
class-decorators-ts.umd.js.map
index.d.ts
package.json
src
index.ts
tsconfig.json
Build \\"classDecoratorsTs\\" to dist:
333 B: class-decorators-ts.js.gz
276 B: class-decorators-ts.js.br
331 B: class-decorators-ts.mjs.gz
271 B: class-decorators-ts.mjs.br
393 B: class-decorators-ts.umd.js.gz
352 B: class-decorators-ts.umd.js.br"
`;

exports[`fixtures class-properties 1`] = `
"Used script: microbundle
Expand Down Expand Up @@ -232,6 +261,35 @@ Build \\"customSrc\\" to dist:
212 B: custom-src.umd.js.br"
`;

exports[`fixtures esnext-ts 1`] = `
"Used script: microbundle --raw
Directory tree:
esnext-ts
dist
esnext-ts.js
esnext-ts.js.map
esnext-ts.mjs
esnext-ts.mjs.map
esnext-ts.umd.js
esnext-ts.umd.js.map
index.d.ts
package.json
src
index.ts
tsconfig.json
Build \\"esnextTs\\" to dist:
470 B: esnext-ts.js.gz
404 B: esnext-ts.js.br
470 B: esnext-ts.mjs.gz
409 B: esnext-ts.mjs.br
528 B: esnext-ts.umd.js.gz
461 B: esnext-ts.umd.js.br"
`;

exports[`fixtures jsx 1`] = `
"Used script: microbundle
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/class-decorators-ts/package.json
@@ -0,0 +1,6 @@
{
"name": "class-decorators-ts",
"scripts": {
"build": "microbundle --raw"
}
}
17 changes: 17 additions & 0 deletions test/fixtures/class-decorators-ts/src/index.ts
@@ -0,0 +1,17 @@
function sealed(constructor: Function) {
Object.seal(constructor);
Object.seal(constructor.prototype);
}

@sealed
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return 'Hello, ' + this.greeting;
}
}

export default new Greeter('Hello World');
6 changes: 6 additions & 0 deletions test/fixtures/class-decorators-ts/tsconfig.json
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"rootDir": "./src",
"experimentalDecorators": true
}
}
6 changes: 6 additions & 0 deletions test/fixtures/esnext-ts/package.json
@@ -0,0 +1,6 @@
{
"name": "esnext-ts",
"scripts": {
"build": "microbundle --raw"
}
}
10 changes: 10 additions & 0 deletions test/fixtures/esnext-ts/src/index.ts
@@ -0,0 +1,10 @@
export default async function foo() {
const out = [];
for await (const item of [1,2]) {
out.push(item);
}

return out;
}

foo().then(console.log)
5 changes: 5 additions & 0 deletions test/fixtures/esnext-ts/tsconfig.json
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"rootDir": "./src"
}
}

0 comments on commit cebff34

Please sign in to comment.