frankwallis / plugin-typescript

TypeScript loader for SystemJS
MIT License
248 stars 47 forks source link

unexpected token export for interface only file #140

Closed unional closed 8 years ago

unional commented 8 years ago
// interfaces.ts
export interface foo { ...}

// index.ts
export * from './interfaces';
export * from './otherFiles';

When I load it on karma with electron, it fails with:

Error: SyntaxError Unexpected token export
  at Object.eval (.../src/index.ts!transpiled:9:10)
  at eval (.../src/index.ts!transpiled:14:4)
  at eval (.../src/index.ts!transpiled:15:3)
  at Object.eval (.../spec/index.spec.ts!transpiled:9:22)
Evaluating .../src/interfaces.ts
...
// jspm.config.js
{
  "typescriptOptions": { "tsconfig": "tsconfig.build.json" },
  ...
}

// tsconfig.build.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "newLine": "LF",
    "noImplicitAny": false,
    "outDir": "dist",
    "sourceMap": true,
    "target": "es5"
  },
  "files": [
    "src/index.ts",
    "typings/index.d.ts"
  ]
}

Let me know if you need other information. Thanks Frank 🌷

frankwallis commented 8 years ago

That error indicates to me that interfaces.ts is not being transpiled at all, and the same scenario works in https://github.com/frankwallis/plugin-typescript/blob/master/examples/angular/src/example-types.ts.

Perhaps try adding packages configuration to force interfaces.ts through the plugin?

unional commented 8 years ago

Thanks. Adding meta solves the problem. Upgrading from jspm 0.16 to 0.17 remove that. However, why do I need it? Other typescript files are being transpiled and executed fine.

By the way, in https://github.com/frankwallis/plugin-typescript/blob/master/examples/angular/src/example-types.ts it works probably becuase enum is value, so it does export JS file.

  packages: {
    "myModule": {
      "main": "index.ts",
      "defaultExtension": "ts",
      meta: {
        "*.ts": {
          loader: "plugin-typescript"
        }
      }
    }
  }
frankwallis commented 8 years ago

I don't really have an answer to this, except that if you are type-checking the plugin should be configured with meta. If it is not then it is treated as the internal transpiler rather than a plugin and that means that some of the plugin hooks are not run.