Open Rich-Harris opened 9 years ago
The general theory here is likely to be a bit different than babel - they provide a comprehensive (if occasionally esoteric) Language Services API : https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API
Specifically : https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API#reference-resolution-in-the-language-service
I haven't yet wrapped my brain around the rollup pipeline, so I'm gonna have to tinker with this some! We wrap this service in Broccoli in Angular2 : https://github.com/angular/angular/blob/master/tools/broccoli/broccoli-typescript.ts (which may or may not help you grok this at all....)
Uh... wow. That's a little more complex than I was expecting! I was hoping that it'd be possible to do something along the lines of
ts.transpile( code, {
module: ts.ModuleKind.ES6
});
but it looks like the available module kinds are CommonJS, AMD, UMD, System, and None (which means CommonJS). Hmm.
Yeah, it's ... non trivial, but quite powerful (and nicely usable if you author in TS)
I've got the basic bootstrapping set up, but in your basic test I can't get any of the plugin methods to fire. Thoughts?
scratch that, version mismatch on rollup :D
bleeding edge TS gives us the option we want :+1: this is gonna need a lot more work, but step 1 is a go.
I've already created a TypeScript plugin, but didn't have the permissions to create it in the Rollup organization. How about a merge?
works for me!
I think we've both discovered the fatal flaw that @Rich-Harris did - currently we can either emit ES6 with import/export syntax, or emit ES5 with cjs, but so far not both.
This might mean dropping into the language services API and getting our AST on, though I've dropped a line to the TS folks asking if they've got any hints.
I just realised that we can depend on prerelease versions from NPM! rollup-plugin-typescript
supports both features as of version 0.2.0
! :rocket:
@Victorystick Nice! Easiest thing is probably just to move your repo into the Rollup organisation – I've move this one out of the way so that that's possible
@Rich-Harris Go ahead! I'll move it in!
@Rich-Harris Apparently I need admin access to the organisation to transfer ownership. :expressionless:
@Victorystick fixed!
Am totally new to TypeScript, so not entirely sure what combination of compiler options will generate ES5 code but with ES6 module imports/exports. Without that, this plugin won't do anything useful!