Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
b3831e8b
Commit
b3831e8b
authored
Dec 20, 2016
by
Alex Beregszaszi
Committed by
GitHub
Dec 20, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #354 from ethereum/move-imports
Move import processing from the compiler
parents
478fe25f
21d78d1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
29 deletions
+39
-29
app.js
src/app.js
+28
-1
compiler.js
src/app/compiler.js
+11
-28
No files found.
src/app.js
View file @
b3831e8b
...
@@ -424,8 +424,35 @@ var run = function () {
...
@@ -424,8 +424,35 @@ var run = function () {
cb
(
err
||
'Unknown transport error'
)
cb
(
err
||
'Unknown transport error'
)
})
})
}
}
// FIXME: at some point we should invalidate the cache
var
cachedRemoteFiles
=
{}
function
handleImportCall
(
url
,
cb
)
{
var
githubMatch
if
(
editor
.
hasFile
(
url
))
{
cb
(
null
,
editor
.
getFile
(
url
))
}
else
if
(
url
in
cachedRemoteFiles
)
{
cb
(
null
,
cachedRemoteFiles
[
url
])
}
else
if
((
githubMatch
=
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)\/(
.*
)
/
.
exec
(
url
)))
{
handleGithubCall
(
githubMatch
[
3
],
githubMatch
[
4
],
function
(
err
,
content
)
{
if
(
err
)
{
cb
(
'Unable to import "'
+
url
+
'": '
+
err
)
return
}
cachedRemoteFiles
[
url
]
=
content
cb
(
null
,
content
)
})
}
else
if
(
/^
[^
:
]
*:
\/\/
/
.
exec
(
url
))
{
cb
(
'Unable to import "'
+
url
+
'": Unsupported URL'
)
}
else
{
cb
(
'Unable to import "'
+
url
+
'": File not found'
)
}
}
var
executionContext
=
new
ExecutionContext
()
var
executionContext
=
new
ExecutionContext
()
var
compiler
=
new
Compiler
(
editor
,
handle
Github
Call
)
var
compiler
=
new
Compiler
(
editor
,
handle
Import
Call
)
var
formalVerification
=
new
FormalVerification
(
$
(
'#verificationView'
),
compiler
.
event
)
var
formalVerification
=
new
FormalVerification
(
$
(
'#verificationView'
),
compiler
.
event
)
var
offsetToLineColumnConverter
=
new
OffsetToLineColumnConverter
(
compiler
.
event
)
var
offsetToLineColumnConverter
=
new
OffsetToLineColumnConverter
(
compiler
.
event
)
...
...
src/app/compiler.js
View file @
b3831e8b
...
@@ -11,14 +11,13 @@ var EventManager = require('../lib/eventManager')
...
@@ -11,14 +11,13 @@ var EventManager = require('../lib/eventManager')
/*
/*
trigger compilationFinished, compilerLoaded, compilationStarted
trigger compilationFinished, compilerLoaded, compilationStarted
*/
*/
function
Compiler
(
editor
,
handle
Github
Call
)
{
function
Compiler
(
editor
,
handle
Import
Call
)
{
var
self
=
this
var
self
=
this
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
var
compileJSON
var
compileJSON
var
compilerAcceptsMultipleFiles
var
compilerAcceptsMultipleFiles
var
cachedRemoteFiles
=
{}
var
worker
=
null
var
worker
=
null
var
currentVersion
var
currentVersion
...
@@ -219,14 +218,12 @@ function Compiler (editor, handleGithubCall) {
...
@@ -219,14 +218,12 @@ function Compiler (editor, handleGithubCall) {
cb
(
null
,
files
[
editor
.
getCacheFile
()])
cb
(
null
,
files
[
editor
.
getCacheFile
()])
return
return
}
}
// FIXME: This will only match imports if the file begins with one.
// FIXME: This will only match imports if the file begins with one.
// It should tokenize by lines and check each.
// It should tokenize by lines and check each.
// eslint-disable-next-line no-useless-escape
// eslint-disable-next-line no-useless-escape
var
importRegex
=
/^
\s
*import
\s
*
[\'\"]([^\'\"]
+
)[\'\"]
;/g
var
importRegex
=
/^
\s
*import
\s
*
[\'\"]([^\'\"]
+
)[\'\"]
;/g
var
reloop
=
false
var
githubMatch
do
{
reloop
=
false
for
(
var
fileName
in
files
)
{
for
(
var
fileName
in
files
)
{
var
match
var
match
while
((
match
=
importRegex
.
exec
(
files
[
fileName
])))
{
while
((
match
=
importRegex
.
exec
(
files
[
fileName
])))
{
...
@@ -241,39 +238,25 @@ function Compiler (editor, handleGithubCall) {
...
@@ -241,39 +238,25 @@ function Compiler (editor, handleGithubCall) {
}
}
}
}
}
}
while
(
importHints
.
length
>
0
)
{
while
(
importHints
.
length
>
0
)
{
var
m
=
importHints
.
pop
()
var
m
=
importHints
.
pop
()
if
(
m
in
files
)
{
if
(
m
in
files
)
{
continue
continue
}
}
if
(
editor
.
hasFile
(
m
))
{
files
[
m
]
=
editor
.
getFile
(
m
)
reloop
=
true
}
else
if
(
m
in
cachedRemoteFiles
)
{
files
[
m
]
=
cachedRemoteFiles
[
m
]
reloop
=
true
}
else
if
((
githubMatch
=
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)\/(
.*
)
/
.
exec
(
m
)))
{
handleGithubCall
(
githubMatch
[
3
],
githubMatch
[
4
],
function
(
err
,
content
)
{
if
(
err
)
{
cb
(
'Unable to import "'
+
m
+
'": '
+
err
)
return
}
cachedRemoteFiles
[
m
]
=
content
handleImportCall
(
m
,
function
(
err
,
content
)
{
if
(
err
)
{
cb
(
err
)
}
else
{
files
[
m
]
=
content
files
[
m
]
=
content
gatherImports
(
files
,
importHints
,
cb
)
gatherImports
(
files
,
importHints
,
cb
)
}
})
})
return
}
else
if
(
/^
[^
:
]
*:
\/\/
/
.
exec
(
m
))
{
cb
(
'Unable to import "'
+
m
+
'": Unsupported URL'
)
return
}
else
{
cb
(
'Unable to import "'
+
m
+
'": File not found'
)
return
return
}
}
}
}
while
(
reloop
)
cb
(
null
,
{
'sources'
:
files
})
cb
(
null
,
{
'sources'
:
files
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment