Merge pull request #5707 from atom/bf-grim-6to5

Report deprecation warning when 'use 6to5' is used instead of 'use babel'.
This commit is contained in:
Kevin Sawicki
2015-02-25 10:07:39 -08:00
2 changed files with 40 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ crypto = require 'crypto'
fs = require 'fs-plus'
path = require 'path'
babel = null # Defer until used
Grim = null # Defer until used
stats =
hits: 0
@@ -132,10 +133,30 @@ transpile = (sourceCode, filePath, cachePath) ->
# either generated on the fly or pulled from cache.
loadFile = (module, filePath) ->
sourceCode = fs.readFileSync(filePath, 'utf8')
return module._compile(sourceCode, filePath) unless sourceCode.startsWith('"use 6to5"') or
sourceCode.startsWith("'use 6to5'") or
sourceCode.startsWith('"use babel"') or
sourceCode.startsWith("'use babel'")
if 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
# which limits the depth to 3
Grim ?= require 'grim'
stack = [
{
fileName: __filename
functionName: 'loadFile'
location: "#{__filename}:161:5"
}
{
fileName: filePath
functionName: '<unknown>'
location: "#{filePath}:1:1"
}
]
deprecation =
message: "Use the 'use babel' pragma instead of 'use 6to5'"
stacks: [stack]
Grim.addSerializedDeprecation(deprecation)
else
return module._compile(sourceCode, filePath)
cachePath = getCachePath(sourceCode)
js = getCachedJavaScript(cachePath) ? transpile(sourceCode, filePath, cachePath)