mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Report a deprecation warning when 'use 6to5' is used instead of 'use babel'.
This commit is contained in:
@@ -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
|
||||
@@ -127,15 +128,33 @@ transpile = (sourceCode, filePath, cachePath) ->
|
||||
|
||||
js
|
||||
|
||||
isRoot = (filePath) ->
|
||||
parts = path.parse(filePath)
|
||||
parts.root == filePath
|
||||
|
||||
# Function that obeys the contract of an entry in the require.extensions map.
|
||||
# Returns the transpiled version of the JavaScript code at filePath, which is
|
||||
# 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'")
|
||||
packageName
|
||||
directory = filePath
|
||||
until packageName
|
||||
directory = path.dirname(directory)
|
||||
manifest = path.join(directory, 'package.json')
|
||||
if fs.existsSync(manifest)
|
||||
json = JSON.parse(fs.readFileSync(manifest))
|
||||
packageName = json.name
|
||||
else if isRoot(directory)
|
||||
break
|
||||
|
||||
Grim ?= require 'grim'
|
||||
Grim.deprecate("Use the 'use babel' pragma instead of 'use 6to5' in #{filePath}", {packageName})
|
||||
else
|
||||
return module._compile(sourceCode, filePath)
|
||||
|
||||
cachePath = getCachePath(sourceCode)
|
||||
js = getCachedJavaScript(cachePath) ? transpile(sourceCode, filePath, cachePath)
|
||||
|
||||
Reference in New Issue
Block a user