diff --git a/spec/babel-spec.coffee b/spec/babel-spec.coffee index 400e5c03e..9e9195783 100644 --- a/spec/babel-spec.coffee +++ b/spec/babel-spec.coffee @@ -42,6 +42,11 @@ describe "Babel transpiler support", -> transpiled = require('./fixtures/babel/flow-comment.js') expect(transpiled(3)).toBe 4 + describe 'when a .js file starts with // @flow', -> + it "transpiles it using babel", -> + transpiled = require('./fixtures/babel/flow-slash-comment.js') + expect(transpiled(3)).toBe 4 + describe "when a .js file does not start with 'use babel';", -> it "does not transpile it using babel", -> spyOn(console, 'error') diff --git a/spec/fixtures/babel/flow-slash-comment.js b/spec/fixtures/babel/flow-slash-comment.js new file mode 100644 index 000000000..b73cc7833 --- /dev/null +++ b/spec/fixtures/babel/flow-slash-comment.js @@ -0,0 +1,4 @@ +// @flow + +const f: Function = v => v + 1 +module.exports = f diff --git a/src/babel.js b/src/babel.js index a944f2e8c..8476a33c0 100644 --- a/src/babel.js +++ b/src/babel.js @@ -11,7 +11,8 @@ var PREFIXES = [ '/** @babel */', '"use babel"', '\'use babel\'', - '/* @flow */' + '/* @flow */', + '// @flow' ] var PREFIX_LENGTH = Math.max.apply(Math, PREFIXES.map(function (prefix) {