Merge pull request #10708 from atom/flow-implies-babel

Flow implies Babel
This commit is contained in:
Josh Abernathy
2016-02-05 17:30:06 -05:00
4 changed files with 12 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ BABEL_PREFIXES = [
"'use babel'"
'"use babel"'
'/** @babel */'
'/* @flow */'
]
PREFIX_LENGTH = Math.max(BABEL_PREFIXES.map((prefix) -> prefix.length)...)

View File

@@ -36,6 +36,11 @@ describe "Babel transpiler support", ->
transpiled = require('./fixtures/babel/babel-double-quotes.js')
expect(transpiled(3)).toBe 4
describe 'when a .js file starts with /* @flow */', ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/flow-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", ->
expect(-> require('./fixtures/babel/invalid.js')).toThrow()

4
spec/fixtures/babel/flow-comment.js vendored Normal file
View File

@@ -0,0 +1,4 @@
/* @flow */
const f: Function = v => v + 1
module.exports = f

View File

@@ -10,7 +10,8 @@ var babelVersionDirectory = null
var PREFIXES = [
'/** @babel */',
'"use babel"',
'\'use babel\''
'\'use babel\'',
'/* @flow */'
]
var PREFIX_LENGTH = Math.max.apply(Math, PREFIXES.map(function (prefix) {