TypeScript 2.3.1 breaking changes in SystemJS plunk

Here is the official Angular + TypeScript plunk that uses SystemJS 0.19.31 and was changed to use TypeScript 2.3 0.0.

When SystemJS config of the same plunk is changed to TypeScript 2.3.1 or 2.3.2

'typescript': 'npm:typescript@2.3.1/lib/typescript.js'

      

it just stops working. There are no errors in the console.

What's the problem with TypeScript 2.3.1? Is this a known issue? Is the problem specific to the current setup?

+3


source to share


1 answer


This is a problem with the automatic detection of the SystemJS module format.

This is a regex to check if the source is es6 and needs to be rewritten:

  // good enough ES6 module detection regex - format detections not designed to be accurate, but to handle the 99% use case
  var esmRegEx = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/;

      

Of course TypeScript 2.3.1 and 2.3.2 have this comment in their source code that matches this regex:



  // For an export of a module, we may be in a declaration file, and it may be accessed elsewhere. E.g.:
  //     declare module "a" { export type T = number; }
  //     declare module "b" { import { T } from "a"; export const x: T; }

      

So when you debug this, you can see that SystemJS loads the transpiler (typescript), detects that it is es6 and needs to be dragged, loads the transpiler, ... and never translates your code ( main.ts

)

The correct format for TypeScript is global, so adding it to the SystemJS config at the top level should fix:

  meta: {typescript: {format: 'global'}}

      

+3


source







All Articles