Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Update dependencies #93

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@
"lint": "eslint src test/*.js",
"pretest": "npm run build",
"test": "mocha --compilers js:buble/register",
"postinstall": "npm run build",
"posttest": "npm run lint",
"prepare": "npm run build",
"prepublish": "npm run test"
},
"dependencies": {
"compare-versions": "2.0.1",
"compare-versions": "3.0.1",
"object-assign": "^4.0.1",
"rollup-pluginutils": "^1.3.1",
"tippex": "^2.1.1",
"typescript": "^1.8.9"
"rollup-pluginutils": "^2.0.1",
"tippex": "^3.0.0",
"typescript": "^2.4.2"
},
"devDependencies": {
"buble": "^0.13.1",
"eslint": "^2.13.1",
"buble": "^0.15.2",
"eslint": "^4.3.0",
"mocha": "^3.0.0",
"rimraf": "^2.5.4",
"rollup": "^0.34.3",
"rollup-plugin-buble": "^0.13.0"
"rollup": "^0.45.2",
"rollup-plugin-buble": "^0.15.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function typescript ( options ) {
return {
// Always append an import for the helpers.
code: transformed.outputText +
`\nimport { __assign, __awaiter, __extends, __decorate, __metadata, __param } from '${helpersId}';`,
`\nimport { __assign, __generator, __awaiter, __extends, __decorate, __metadata, __param } from '${helpersId}';`,

// Rollup expects `map` to be an object so we must parse the string
map: transformed.sourceMapText ? JSON.parse(transformed.sourceMapText) : null
Expand Down
32 changes: 30 additions & 2 deletions src/typescript-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,39 @@ export function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}

export function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};

export function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
86 changes: 46 additions & 40 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ process.chdir( __dirname );
function evaluate ( bundle ) {
const module = { exports: {} };

new Function( 'module', 'exports', bundle.generate({ format: 'cjs' }).code )( module, module.exports );

return module.exports;
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
new Function( 'module', 'exports', code )( module, module.exports );
return module.exports;
});
}

// Short-hand for rollup using the typescript plugin.
Expand All @@ -27,10 +28,10 @@ describe( 'rollup-plugin-typescript', function () {

it( 'runs code through typescript', () => {
return bundle( 'sample/basic/main.ts' ).then( bundle => {
const code = bundle.generate().code;

assert.ok( code.indexOf( 'number' ) === -1, code );
assert.ok( code.indexOf( 'const' ) === -1, code );
return bundle.generate().then(({ code }) => {
assert.ok( code.indexOf( 'number' ) === -1, code );
assert.ok( code.indexOf( 'const' ) === -1, code );
});
});
});

Expand All @@ -41,42 +42,42 @@ describe( 'rollup-plugin-typescript', function () {
it( 'handles async functions', () => {
return bundle( 'sample/async/main.ts' )
.then( bundle => {
const wait = evaluate( bundle );

return wait( 3 );
return evaluate( bundle ).then(wait => {
return wait( 3 );
});
});
});

it( 'does not duplicate helpers', () => {
return bundle( 'sample/dedup-helpers/main.ts' ).then( bundle => {
const code = bundle.generate().code;
return bundle.generate().then(({ code }) => {
// The `__extends` function is defined in the bundle.
assert.ok( code.indexOf( 'function __extends' ) > -1, code );

// The `__extends` function is defined in the bundle.
assert.ok( code.indexOf( 'function __extends' ) > -1, code );

// No duplicate `__extends` helper is defined.
assert.equal( code.indexOf( '__extends$1' ), -1, code );
// No duplicate `__extends` helper is defined.
assert.equal( code.indexOf( '__extends$1' ), -1, code );
});
});
});

it( 'transpiles `export class A` correctly', () => {
return bundle( 'sample/export-class-fix/main.ts' ).then( bundle => {
const code = bundle.generate().code;

assert.equal( code.indexOf( 'class' ), -1, code );
assert.ok( code.indexOf( 'var A = (function' ) !== -1, code );
assert.ok( code.indexOf( 'var B = (function' ) !== -1, code );
assert.ok( code.indexOf( 'export { A, B };' ) !== -1, code );
return bundle.generate().then(({ code }) => {
assert.equal( code.indexOf( 'class' ), -1, code );
assert.ok( code.indexOf( 'var A = (function' ) !== -1, code );
assert.ok( code.indexOf( 'var B = (function' ) !== -1, code );
assert.ok( code.indexOf( 'export { A, B };' ) !== -1, code );
});
});
});

it( 'transpiles ES6 features to ES5 with source maps', () => {
return bundle( 'sample/import-class/main.ts' ).then( bundle => {
const code = bundle.generate().code;

assert.equal( code.indexOf( 'class' ), -1, code );
assert.equal( code.indexOf( '...' ), -1, code );
assert.equal( code.indexOf( '=>' ), -1, code );
return bundle.generate().then(({ code }) => {
assert.equal( code.indexOf( 'class' ), -1, code );
assert.equal( code.indexOf( '...' ), -1, code );
assert.equal( code.indexOf( '=>' ), -1, code );
});
});
});

Expand All @@ -88,14 +89,17 @@ describe( 'rollup-plugin-typescript', function () {

it( 'works with named exports for abstract classes', () => {
return bundle( 'sample/export-abstract-class/main.ts' ).then(bundle => {
const code = bundle.generate().code;
assert.ok( code.length > 0, code );
return bundle.generate().then(({ code }) => {
assert.ok( code.length > 0, code );
});
});
});

it( 'should use named exports for classes', () => {
return bundle( 'sample/export-class/main.ts' ).then( bundle => {
assert.equal( evaluate( bundle ).foo, 'bar' );
return evaluate( bundle ).then(result => {
assert.equal( result.foo, 'bar' );
});
});
});

Expand All @@ -118,7 +122,9 @@ describe( 'rollup-plugin-typescript', function () {
}
})
}).then( bundle => {
assert.equal( evaluate( bundle ), 1337 );
return evaluate( bundle ).then(result => {
assert.equal( result, 1337 );
});
});
});

Expand Down Expand Up @@ -177,14 +183,14 @@ describe( 'rollup-plugin-typescript', function () {

it( 'should transpile JSX if enabled', () => {
return bundle( 'sample/jsx/main.tsx', { jsx: 'react' }).then( bundle => {
const code = bundle.generate().code;

assert.notEqual( code.indexOf( 'const __assign = ' ), -1,
'should contain __assign definition' );
return bundle.generate().then(({ code }) => {
assert.notEqual( code.indexOf( 'const __assign = ' ), -1,
'should contain __assign definition' );

const usage = code.indexOf( 'React.createElement("span", __assign({}, props), "Yo!")' );
const usage = code.indexOf( 'React.createElement("span", __assign({}, props), "Yo!")' );

assert.notEqual( usage, -1, 'should contain usage' );
assert.notEqual( usage, -1, 'should contain usage' );
});
});
});

Expand Down Expand Up @@ -213,11 +219,11 @@ describe( 'rollup-plugin-typescript', function () {
return bundle( 'sample/dedup-helpers/main.ts', {
sourceMap: true
}).then( bundle => {
const { map } = bundle.generate({
return bundle.generate({
sourceMap: true
}).then(({ map }) => {
assert.ok( map.sources.every( source => source.indexOf( 'typescript-helpers' ) === -1) );
});

assert.ok( map.sources.every( source => source.indexOf( 'typescript-helpers' ) === -1) );
});
});
});
Expand Down
Loading