FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atom/src/babel.js at master · githubhjs/atom · GitHub
githubhjs
/
atom
Public
forked from
atom/atom
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atom
/
src
/
babel.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (53 loc) · 1.49 KB
Breadcrumbs
atom
/
src
/
babel.js
Copy path
File metadata and controls
63 lines (53 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
var
crypto
=
require
(
'crypto'
)
var
path
=
require
(
'path'
)
var
defaultOptions
=
require
(
'../static/babelrc.json'
)
var
babel
=
null
var
babelVersionDirectory
=
null
var
PREFIXES
=
[
'/** @babel */'
,
'"use babel"'
,
'\'use babel\''
]
var
PREFIX_LENGTH
=
Math
.
max
.
apply
(
Math
,
PREFIXES
.
map
(
function
(
prefix
)
{
return
prefix
.
length
}
)
)
exports
.
shouldCompile
=
function
(
sourceCode
)
{
var
start
=
sourceCode
.
substr
(
0
,
PREFIX_LENGTH
)
return
PREFIXES
.
some
(
function
(
prefix
)
{
return
start
.
indexOf
(
prefix
)
===
0
}
)
}
exports
.
getCachePath
=
function
(
sourceCode
)
{
if
(
babelVersionDirectory
==
null
)
{
var
babelVersion
=
require
(
'babel-core/package.json'
)
.
version
babelVersionDirectory
=
path
.
join
(
'js'
,
'babel'
,
createVersionAndOptionsDigest
(
babelVersion
,
defaultOptions
)
)
}
return
path
.
join
(
babelVersionDirectory
,
crypto
.
createHash
(
'sha1'
)
.
update
(
sourceCode
,
'utf8'
)
.
digest
(
'hex'
)
+
'.js'
)
}
exports
.
compile
=
function
(
sourceCode
,
filePath
)
{
if
(
!
babel
)
{
babel
=
require
(
'babel-core'
)
}
var
options
=
{
filename
:
filePath
}
for
(
var
key
in
defaultOptions
)
{
options
[
key
]
=
defaultOptions
[
key
]
}
return
babel
.
transform
(
sourceCode
,
options
)
.
code
}
function
createVersionAndOptionsDigest
(
version
,
options
)
{
return
crypto
.
createHash
(
'sha1'
)
.
update
(
'babel-core'
,
'utf8'
)
.
update
(
'\0'
,
'utf8'
)
.
update
(
version
,
'utf8'
)
.
update
(
'\0'
,
'utf8'
)
.
update
(
JSON
.
stringify
(
options
)
,
'utf8'
)
.
digest
(
'hex'
)
}
Back
|
FazBrowse Home
|
New Git URL