Honor /** use babel */ in addition to 'use babel'

This commit is contained in:
Max Brunsfeld
2015-08-18 15:49:34 -07:00
parent ca58687c88
commit e4b1d512cd
3 changed files with 10 additions and 1 deletions

View File

@@ -33,6 +33,12 @@ describe "Babel transpiler support", ->
observedDigest = babel.createBabelVersionAndOptionsDigest(version, defaultOptions)
expect(observedDigest).toEqual expectedDigest
describe 'when a .js file starts with /** use babel */;', ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/babel-comment.js')
expect(transpiled(3)).toBe 4
expect(grim.getDeprecationsLength()).toBe 0
describe "when a .js file starts with 'use babel';", ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/babel-single-quotes.js')

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

@@ -0,0 +1,3 @@
/** use babel */
module.exports = v => v + 1

View File

@@ -142,7 +142,7 @@ transpile = (sourceCode, filePath, cachePath) ->
# either generated on the fly or pulled from cache.
loadFile = (module, filePath) ->
sourceCode = fs.readFileSync(filePath, 'utf8')
if sourceCode.startsWith('"use babel"') or sourceCode.startsWith("'use babel'")
if sourceCode.startsWith('"use babel"') or sourceCode.startsWith("'use babel'") or sourceCode.startsWith('/** use babel */')
# Continue.
else if sourceCode.startsWith('"use 6to5"') or sourceCode.startsWith("'use 6to5'")
# Create a manual deprecation since the stack is too deep to use Grim