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
6a3f5a03
Commit
6a3f5a03
authored
Oct 16, 2015
by
chriseth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #54 from chriseth/multiErrors
Improved import
parents
91bb93d8
1e325dd0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
46 deletions
+115
-46
README.md
README.md
+14
-2
index.html
index.html
+74
-32
index.js
index.js
+17
-6
package.json
package.json
+1
-1
worker.js
worker.js
+9
-5
No files found.
README.md
View file @
6a3f5a03
...
@@ -15,4 +15,17 @@ And then use it like so:
...
@@ -15,4 +15,17 @@ And then use it like so:
var input = "contract x { function g() {} }";
var input = "contract x { function g() {} }";
var output = solc.compile(input, 1); // 1 activates the optimiser
var output = solc.compile(input, 1); // 1 activates the optimiser
for (var contractName in output.contracts)
for (var contractName in output.contracts)
console.log(contractName + ': ' + output.contracts
[
contractName
]
.bytecode);
console.log(contractName + ': ' + output.contracts[contractName].bytecode);
\ No newline at end of file
Starting from version 0.1.6, multiple files are supported with automatic import resolution by the compiler as follows:
var solc = require('solc');
var input = {
'lib.sol': 'library L { function f() returns (uint) { return 7; } }',
'cont.sol': 'import "lib.sol"; contract x { function g() { L.f(); } }'
};
var output = solc.compile({sources: input}, 1);
for (var contractName in output.contracts)
console.log(contractName + ': ' + output.contracts[contractName].bytecode);
Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own.
index.html
View file @
6a3f5a03
...
@@ -475,6 +475,7 @@
...
@@ -475,6 +475,7 @@
// ----------------- compiler ----------------------
// ----------------- compiler ----------------------
var
compileJSON
;
var
compileJSON
;
var
compilerAcceptsMultipleFiles
;
var
previousInput
=
''
;
var
previousInput
=
''
;
var
sourceAnnotations
=
[];
var
sourceAnnotations
=
[];
...
@@ -487,11 +488,13 @@
...
@@ -487,11 +488,13 @@
var
input
=
editor
.
getValue
();
var
input
=
editor
.
getValue
();
window
.
localStorage
.
setItem
(
SOL_CACHE_FILE
,
input
);
window
.
localStorage
.
setItem
(
SOL_CACHE_FILE
,
input
);
var
inputIncludingImports
=
includeLocalAndRemoteImports
(
input
,
compile
);
var
files
=
{};
if
(
!
inputIncludingImports
)
return
;
files
[
fileNameFromKey
(
SOL_CACHE_FILE
)]
=
input
;
var
input
=
gatherImports
(
files
,
compile
);
if
(
!
input
)
return
;
var
optimize
=
document
.
querySelector
(
'#optimize'
).
checked
;
var
optimize
=
document
.
querySelector
(
'#optimize'
).
checked
;
compileJSON
(
input
IncludingImports
,
optimize
?
1
:
0
);
compileJSON
(
input
,
optimize
?
1
:
0
);
};
};
var
compilationFinished
=
function
(
result
)
{
var
compilationFinished
=
function
(
result
)
{
var
data
=
$
.
parseJSON
(
result
);
var
data
=
$
.
parseJSON
(
result
);
...
@@ -527,7 +530,14 @@
...
@@ -527,7 +530,14 @@
var
onCompilerLoaded
=
function
()
{
var
onCompilerLoaded
=
function
()
{
if
(
worker
===
null
)
{
if
(
worker
===
null
)
{
var
compile
=
Module
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
var
compile
;
if
(
'_compileJSONMulti'
in
Module
)
{
compilerAcceptsMultipleFiles
=
true
;
compile
=
Module
.
cwrap
(
"compileJSONMulti"
,
"string"
,
[
"string"
,
"number"
]);
}
else
{
compilerAcceptsMultipleFiles
=
false
;
compile
=
Module
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
}
compileJSON
=
function
(
source
,
optimize
,
cb
)
{
compileJSON
=
function
(
source
,
optimize
,
cb
)
{
try
{
try
{
var
result
=
compile
(
source
,
optimize
);
var
result
=
compile
(
source
,
optimize
);
...
@@ -543,24 +553,46 @@
...
@@ -543,24 +553,46 @@
};
};
var
cachedRemoteFiles
=
{};
var
cachedRemoteFiles
=
{};
function
includeLocalAndRemoteImports
(
input
,
asyncCallback
,
needAsync
)
{
function
gatherImports
(
files
,
asyncCallback
,
needAsync
)
{
if
(
!
compilerAcceptsMultipleFiles
)
return
files
[
fileNameFromKey
(
SOL_CACHE_FILE
)];
var
importRegex
=
/import
\s[\'\"]([^\'\"]
+
)[\'\"]
;/g
;
var
importRegex
=
/import
\s[\'\"]([^\'\"]
+
)[\'\"]
;/g
;
var
match
;
var
reloop
=
false
;
for
(
var
runs
=
0
;
(
match
=
importRegex
.
exec
(
input
))
!==
null
&&
runs
<
100
;
runs
++
)
{
do
{
var
githubMatch
=
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^\/]
*
\/[^\/]
*
)\/(
.*
)
/
.
exec
(
match
[
1
]);
reloop
=
false
;
if
(
getFiles
().
indexOf
(
fileKey
(
match
[
1
]))
!==
-
1
)
for
(
var
fileName
in
files
)
{
input
=
input
.
replace
(
match
[
0
],
window
.
localStorage
.
getItem
(
fileKey
(
match
[
1
])
));
var
match
;
else
if
(
match
[
1
]
in
cachedRemoteFiles
)
while
(
match
=
importRegex
.
exec
(
files
[
fileName
]))
{
input
=
input
.
replace
(
match
[
0
],
cachedRemoteFiles
[
match
[
1
]]);
var
m
=
match
[
1
];
else
if
(
githubMatch
)
{
if
(
m
in
files
)
continue
;
$
.
getJSON
(
'https://api.github.com/repos/'
+
githubMatch
[
3
]
+
'/contents/'
+
githubMatch
[
4
],
function
(
result
)
{
if
(
getFiles
().
indexOf
(
fileKey
(
m
))
!==
-
1
)
{
var
content
=
Base64
.
decode
(
result
.
content
);
files
[
m
]
=
window
.
localStorage
[
fileKey
(
match
[
1
])];
cachedRemoteFiles
[
match
[
1
]]
=
content
;
reloop
=
true
;
includeLocalAndRemoteImports
(
input
.
replace
(
match
[
0
],
content
),
asyncCallback
,
true
);
}
else
if
(
m
in
cachedRemoteFiles
)
{
});
files
[
m
]
=
cachedRemoteFiles
[
m
];
return
null
;
reloop
=
true
;
}
else
if
(
githubMatch
=
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^\/]
*
\/[^\/]
*
)\/(
.*
)
/
.
exec
(
m
))
{
$
.
getJSON
(
'https://api.github.com/repos/'
+
githubMatch
[
3
]
+
'/contents/'
+
githubMatch
[
4
],
function
(
result
)
{
var
content
;
if
(
'content'
in
result
)
content
=
Base64
.
decode
(
result
.
content
);
else
content
=
"
\"
"
+
m
+
"
\"
NOT FOUND"
;
//@TODO handle this better
cachedRemoteFiles
[
m
]
=
content
;
files
[
m
]
=
content
;
gatherImports
(
files
,
asyncCallback
,
true
);
}).
fail
(
function
(){
var
content
=
"
\"
"
+
m
+
"
\"
NOT FOUND"
;
//@TODO handle this better
cachedRemoteFiles
[
m
]
=
content
;
files
[
m
]
=
content
;
gatherImports
(
files
,
asyncCallback
,
true
);
});
return
null
;
}
}
}
}
}
}
while
(
reloop
);
var
input
=
JSON
.
stringify
({
'sources'
:
files
});
if
(
needAsync
)
if
(
needAsync
)
asyncCallback
(
input
);
asyncCallback
(
input
);
return
input
;
return
input
;
...
@@ -575,6 +607,7 @@
...
@@ -575,6 +607,7 @@
switch
(
data
.
cmd
)
{
switch
(
data
.
cmd
)
{
case
'versionLoaded'
:
case
'versionLoaded'
:
$
(
'#version'
).
text
(
data
.
data
);
$
(
'#version'
).
text
(
data
.
data
);
compilerAcceptsMultipleFiles
=
!!
data
.
acceptsMultipleFiles
;
onCompilerLoaded
();
onCompilerLoaded
();
break
;
break
;
case
'compiled'
:
case
'compiled'
:
...
@@ -622,7 +655,7 @@
...
@@ -622,7 +655,7 @@
var
detailsOpen
=
{};
var
detailsOpen
=
{};
function
errortype
(
message
)
{
function
errortype
(
message
)
{
return
message
.
match
(
/^
[
0-9:
]
* Warning: /
)
?
'warning'
:
'error'
;
return
message
.
match
(
/^
.*:
[
0-9
]
*:
[
0-9
]
* Warning: /
)
?
'warning'
:
'error'
;
}
}
var
renderError
=
function
(
message
)
{
var
renderError
=
function
(
message
)
{
...
@@ -630,18 +663,27 @@
...
@@ -630,18 +663,27 @@
var
$pre
=
$
(
"<pre />"
).
text
(
message
);
var
$pre
=
$
(
"<pre />"
).
text
(
message
);
var
$error
=
$
(
'<div class="sol '
+
type
+
'"><div class="close"><i class="fa fa-close"></i></div></div>'
).
prepend
(
$pre
);
var
$error
=
$
(
'<div class="sol '
+
type
+
'"><div class="close"><i class="fa fa-close"></i></div></div>'
).
prepend
(
$pre
);
$
(
'#output'
).
append
(
$error
);
$
(
'#output'
).
append
(
$error
);
var
err
=
message
.
match
(
/^:
([
0-9
]
*
)
:
([
0-9
]
*
)
/
);
var
err
=
message
.
match
(
/^
([^
:
]
*
)
:
([
0-9
]
*
)
:
(([
0-9
]
*
)
:
)?
/
);
if
(
err
&&
err
.
length
)
{
if
(
err
)
{
var
errLine
=
parseInt
(
err
[
1
],
10
)
-
1
;
var
errFile
=
err
[
1
];
var
errCol
=
err
[
2
]
?
parseInt
(
err
[
2
],
10
)
:
0
;
var
errLine
=
parseInt
(
err
[
2
],
10
)
-
1
;
sourceAnnotations
[
sourceAnnotations
.
length
]
=
{
var
errCol
=
err
[
4
]
?
parseInt
(
err
[
4
],
10
)
:
0
;
row
:
errLine
,
if
(
errFile
==
''
||
errFile
==
fileNameFromKey
(
SOL_CACHE_FILE
))
{
column
:
errCol
,
sourceAnnotations
[
sourceAnnotations
.
length
]
=
{
text
:
message
,
row
:
errLine
,
type
:
type
column
:
errCol
,
};
text
:
message
,
editor
.
getSession
().
setAnnotations
(
sourceAnnotations
);
type
:
type
};
editor
.
getSession
().
setAnnotations
(
sourceAnnotations
);
}
$error
.
click
(
function
(
ev
){
$error
.
click
(
function
(
ev
){
if
(
errFile
!=
''
&&
errFile
!=
fileNameFromKey
(
SOL_CACHE_FILE
)
&&
getFiles
().
indexOf
(
fileKey
(
errFile
))
!==
-
1
)
{
// Switch to file
SOL_CACHE_FILE
=
fileKey
(
errFile
);
updateFiles
();
//@TODO could show some error icon in files with errors
}
editor
.
focus
();
editor
.
focus
();
editor
.
gotoLine
(
errLine
+
1
,
errCol
-
1
,
true
);
editor
.
gotoLine
(
errLine
+
1
,
errCol
-
1
,
true
);
});
});
...
...
index.js
View file @
6a3f5a03
var
soljson
=
require
(
'./bin/soljson-latest.js'
);
var
soljson
=
require
(
'./bin/soljson-latest.js'
);
compileJSON
=
soljson
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
var
compileJSON
=
soljson
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
var
compileJSONMulti
=
'_compileJSONMulti'
in
soljson
?
soljson
.
cwrap
(
"compileJSONMulti"
,
"string"
,
[
"string"
,
"number"
])
:
null
;
var
compile
=
function
(
input
,
optimise
)
{
var
result
=
''
;
if
(
typeof
(
input
)
!=
typeof
(
''
)
&&
compileJSONMulti
!==
null
)
result
=
compileJSONMulti
(
JSON
.
stringify
(
input
),
optimise
);
else
result
=
compileJSON
(
input
,
optimise
);
return
JSON
.
parse
(
result
);
}
module
.
exports
=
{
module
.
exports
=
{
compile
:
function
(
input
,
optimise
){
compile
:
compile
,
return
JSON
.
parse
(
compileJSON
(
input
,
optimise
)
);
},
version
:
soljson
.
cwrap
(
"version"
,
"string"
,
[])
version
:
soljson
.
cwrap
(
"version"
,
"string"
,
[])
}
}
\ No newline at end of file
package.json
View file @
6a3f5a03
{
{
"name"
:
"
solc
"
,
"name"
:
"
solc
"
,
"version"
:
"0.1.5"
,
"version"
:
"0.1.5
-multi
"
,
"description"
:
"Solidity compiler"
,
"description"
:
"Solidity compiler"
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
worker.js
View file @
6a3f5a03
...
@@ -10,11 +10,15 @@ addEventListener('message', function(e) {
...
@@ -10,11 +10,15 @@ addEventListener('message', function(e) {
importScripts
(
data
.
data
);
importScripts
(
data
.
data
);
version
=
Module
.
cwrap
(
"version"
,
"string"
,
[]);
version
=
Module
.
cwrap
(
"version"
,
"string"
,
[]);
compileJSON
=
Module
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
if
(
'_compileJSONMulti'
in
Module
)
postMessage
({
cmd
:
'versionLoaded'
,
data
:
version
()});
compileJSON
=
Module
.
cwrap
(
"compileJSONMulti"
,
"string"
,
[
"string"
,
"number"
]);
break
;
else
case
'version'
:
compileJSON
=
Module
.
cwrap
(
"compileJSON"
,
"string"
,
[
"string"
,
"number"
]);
postMessage
({
cmd
:
'versionLoaded'
,
data
:
version
()});
postMessage
({
cmd
:
'versionLoaded'
,
data
:
version
(),
acceptsMultipleFiles
:
(
'_compileJSONMulti'
in
Module
)
});
break
;
break
;
case
'compile'
:
case
'compile'
:
postMessage
({
cmd
:
'compiled'
,
data
:
compileJSON
(
data
.
source
,
data
.
optimize
)});
postMessage
({
cmd
:
'compiled'
,
data
:
compileJSON
(
data
.
source
,
data
.
optimize
)});
...
...
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