Commit d26e762b authored by Alex Beregszaszi's avatar Alex Beregszaszi

Pass previously identified sources to gatherImports

parent 850c41ea
...@@ -26,14 +26,7 @@ function Compiler (editor, handleGithubCall) { ...@@ -26,14 +26,7 @@ function Compiler (editor, handleGithubCall) {
optimize = _optimize optimize = _optimize
} }
var compile = function (missingInputs) { var internalCompile = function (files, missingInputs) {
editor.clearAnnotations()
self.event.trigger('compilationStarted', [])
var input = editor.getValue()
editor.setCacheFileContent(input)
var files = {}
files[utils.fileNameFromKey(editor.getCacheFile())] = input
gatherImports(files, missingInputs, function (input, error) { gatherImports(files, missingInputs, function (input, error) {
if (input === null) { if (input === null) {
self.lastCompilationResult = null self.lastCompilationResult = null
...@@ -43,6 +36,17 @@ function Compiler (editor, handleGithubCall) { ...@@ -43,6 +36,17 @@ function Compiler (editor, handleGithubCall) {
} }
}) })
} }
var compile = function (missingInputs) {
editor.clearAnnotations()
self.event.trigger('compilationStarted', [])
var input = editor.getValue()
editor.setCacheFileContent(input)
var files = {}
files[utils.fileNameFromKey(editor.getCacheFile())] = input
internalCompile(files, missingInputs)
}
this.compile = compile this.compile = compile
function setCompileJSON (_compileJSON) { function setCompileJSON (_compileJSON) {
...@@ -118,7 +122,8 @@ function Compiler (editor, handleGithubCall) { ...@@ -118,7 +122,8 @@ function Compiler (editor, handleGithubCall) {
self.lastCompilationResult = null self.lastCompilationResult = null
self.event.trigger('compilationFinished', [false, data, source]) self.event.trigger('compilationFinished', [false, data, source])
} else if (missingInputs !== undefined && missingInputs.length > 0) { } else if (missingInputs !== undefined && missingInputs.length > 0) {
compile(missingInputs) // try compiling again with the new set of inputs
internalCompile(source.sources, missingInputs)
} else { } else {
self.lastCompilationResult = { self.lastCompilationResult = {
data: data, data: data,
...@@ -210,6 +215,8 @@ function Compiler (editor, handleGithubCall) { ...@@ -210,6 +215,8 @@ function Compiler (editor, handleGithubCall) {
cb(files[editor.getCacheFile()]) cb(files[editor.getCacheFile()])
return return
} }
// FIXME: This will only match imports if the file begins with one.
// 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 reloop = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment