Comparing version 0.1.11-20191225190505.commit-f89a500 to 0.1.11-20191230221721.commit-f7d0ae0
@@ -10,2 +10,3 @@ import { IErrorPositionCapable, PositionCapableError, IPositionCapable } from './NodeError'; | ||
warning(message: string, node: Nodes.Node): void; | ||
removeErrorsFromModule(moduleName: string): void; | ||
hasErrorForBranch(position: IPositionCapable): any; | ||
@@ -12,0 +13,0 @@ hasErrors(): boolean; |
@@ -45,2 +45,5 @@ "use strict"; | ||
} | ||
removeErrorsFromModule(moduleName) { | ||
this.errors = this.errors.filter($ => $.position && $.position.moduleName !== moduleName); | ||
} | ||
hasErrorForBranch(position) { | ||
@@ -47,0 +50,0 @@ return this.errors.some($ => NodeError_1.isSamePositionOrInside(position, $.position) && !$.warning); |
@@ -31,2 +31,3 @@ "use strict"; | ||
}); | ||
this.messageCollector.removeErrorsFromModule(moduleName); | ||
} | ||
@@ -33,0 +34,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
} | ||
async function main(cwd, argv) { | ||
function getParsingContext(cwd, argv) { | ||
NodeSystem_1.nodeSystem.cwd = cwd; | ||
@@ -43,2 +43,3 @@ const parsingContext = new ParsingContext_1.ParsingContext(NodeSystem_1.nodeSystem); | ||
'--desugar': Boolean, | ||
'--watch': Boolean, | ||
'--run': '--test' | ||
@@ -52,2 +53,5 @@ }, { | ||
const DESUGAR = !!args['--desugar']; | ||
const WAST = !!args['--wast']; | ||
const WATCH = !!args['--watch']; | ||
const OPTIMIZE = !args['--no-optimize']; | ||
const file = args._[0]; | ||
@@ -102,10 +106,27 @@ let customAssertions = {}; | ||
mkdirRecursive(outPath); | ||
const codeGen = index_1.compile(parsingContext, mainModule, DEBUG); | ||
const optimize = !args['--no-optimize']; | ||
await codeGen.validate(optimize, DEBUG || args['--wast']); | ||
if (args['--wast']) { | ||
NodeSystem_1.nodeSystem.writeFile(outFileFullWithoutExtension + '.wast', codeGen.emitText()); | ||
return Object.assign(parsingContext, { | ||
mainModule, | ||
options: { | ||
DEBUG, | ||
DESUGAR, | ||
WAST, | ||
OPTIMIZE, | ||
WATCH, | ||
TEST: args['--test'] | ||
}, | ||
outFileFullWithoutExtension, | ||
outPath, | ||
libPaths, | ||
libs, | ||
customAssertions | ||
}); | ||
} | ||
async function emit(parsingContext) { | ||
const codeGen = index_1.compile(parsingContext, parsingContext.mainModule, parsingContext.options.DEBUG); | ||
await codeGen.validate(parsingContext.options.OPTIMIZE, parsingContext.options.DEBUG || parsingContext.options.WAST); | ||
if (parsingContext.options.WAST) { | ||
NodeSystem_1.nodeSystem.writeFile(parsingContext.outFileFullWithoutExtension + '.wast', codeGen.emitText()); | ||
} | ||
if (codeGen.sourceMap) { | ||
NodeSystem_1.nodeSystem.writeFile(NodeSystem_1.nodeSystem.resolvePath(outPath, 'sourceMap.map'), codeGen.sourceMap); | ||
NodeSystem_1.nodeSystem.writeFile(NodeSystem_1.nodeSystem.resolvePath(parsingContext.outPath, 'sourceMap.map'), codeGen.sourceMap); | ||
} | ||
@@ -115,9 +136,9 @@ if (!codeGen.buffer) { | ||
} | ||
fs_1.writeFileSync(outFileFullWithoutExtension + '.wasm', codeGen.buffer); | ||
fs_1.writeFileSync(parsingContext.outFileFullWithoutExtension + '.wasm', codeGen.buffer); | ||
let src = []; | ||
src.push('Object.defineProperty(exports, "__esModule", { value: true });'); | ||
src.push('const modules = [];'); | ||
for (let i in libPaths) { | ||
const path = libPaths[i]; | ||
src.push(`modules.push(require(${JSON.stringify(path_1.relative(path_1.dirname(outFileFullWithoutExtension), path))}).default);`); | ||
for (let i in parsingContext.libPaths) { | ||
const path = parsingContext.libPaths[i]; | ||
src.push(`modules.push(require(${JSON.stringify(path_1.relative(path_1.dirname(parsingContext.outFileFullWithoutExtension), path))}).default);`); | ||
} | ||
@@ -150,8 +171,8 @@ const values = []; | ||
`); | ||
NodeSystem_1.nodeSystem.writeFile(outFileFullWithoutExtension + '.js', src.join('\n')); | ||
if (DESUGAR) { | ||
NodeSystem_1.nodeSystem.writeFile(parsingContext.outFileFullWithoutExtension + '.js', src.join('\n')); | ||
if (parsingContext.options.DESUGAR) { | ||
parsingContext.modulesInContext.forEach(module => { | ||
if (module.fileName.startsWith(NodeSystem_1.nodeSystem.cwd)) { | ||
const relativePath = NodeSystem_1.nodeSystem.relative(NodeSystem_1.nodeSystem.cwd, module.fileName); | ||
const targetFile = NodeSystem_1.nodeSystem.resolvePath(outPath + '/desugar/', relativePath); | ||
const targetFile = NodeSystem_1.nodeSystem.resolvePath(parsingContext.outPath + '/desugar/', relativePath); | ||
mkdirRecursive(path_1.dirname(targetFile)); | ||
@@ -162,4 +183,4 @@ NodeSystem_1.nodeSystem.writeFile(targetFile, nodePrinter_1.printNode(module)); | ||
} | ||
if (args['--test']) { | ||
const testInstance = await testEnvironment_1.generateTestInstance(codeGen.buffer, libs); | ||
if (parsingContext.options.TEST) { | ||
const testInstance = await testEnvironment_1.generateTestInstance(codeGen.buffer, parsingContext.libs); | ||
if (typeof testInstance.exports.test !== 'function') { | ||
@@ -177,6 +198,6 @@ if (typeof testInstance.exports.main !== 'function') { | ||
const testResults = test_1.getTestResults(testInstance); | ||
for (let path in customAssertions) { | ||
for (let path in parsingContext.customAssertions) { | ||
const startTime = Date.now(); | ||
try { | ||
customAssertions[path](() => testInstance); | ||
parsingContext.customAssertions[path](() => testInstance); | ||
testResults.push({ | ||
@@ -220,11 +241,52 @@ title: path, | ||
console.error(colors_1.formatColorAndReset(`\n\n Some tests failed. Passed: ${totalPass} Failed: ${totalTests - totalPass} (${(totalTime / 1000).toFixed(2)}s)\n\n`, colors_1.ForegroundColors.Red)); | ||
process.exit(1); | ||
return false; | ||
} | ||
else { | ||
console.error(colors_1.formatColorAndReset(`\n\n All tests passed. Passed: ${totalPass} Failed: ${totalTests - totalPass} (${(totalTime / 1000).toFixed(2)}s)\n\n`, colors_1.ForegroundColors.Green)); | ||
return true; | ||
} | ||
} | ||
} | ||
return parsingContext.messageCollector.errors.length === 0; | ||
} | ||
async function main(cwd, argv) { | ||
const parsingContext = getParsingContext(cwd, argv); | ||
if (parsingContext.options.WATCH) { | ||
let invalidated = true; | ||
let running = false; | ||
fs_1.watch(cwd, { recursive: true }, (event, fileName) => { | ||
const fqn = parsingContext.getModuleFQNForFile(fileName); | ||
const inContext = parsingContext.modulesInContext.has(fqn); | ||
if (inContext) { | ||
console.log(event, fileName); | ||
parsingContext.invalidateModule(fqn); | ||
invalidated = true; | ||
} | ||
}); | ||
setInterval(async () => { | ||
if (invalidated && !running) { | ||
invalidated = false; | ||
const start = Date.now(); | ||
console.log('Starting incremental compilation...'); | ||
running = true; | ||
emit(parsingContext) | ||
.then(() => { | ||
running = false; | ||
console.log(colors_1.formatColorAndReset('[OK] ' + (Date.now() - start).toFixed(1) + 'ms', colors_1.ForegroundColors.Green)); | ||
}) | ||
.catch(() => { | ||
running = false; | ||
console.log(colors_1.formatColorAndReset('[ERROR] ' + (Date.now() - start).toFixed(1) + 'ms', colors_1.ForegroundColors.Red)); | ||
}); | ||
} | ||
}, 2000); | ||
await new Promise(() => void 0); // wait forever | ||
} | ||
else { | ||
if ((await emit(parsingContext)) === false) { | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
exports.main = main; | ||
//# sourceMappingURL=index-bin.js.map |
{ | ||
"name": "lys", | ||
"version": "0.1.11-20191225190505.commit-f89a500", | ||
"version": "0.1.11-20191230221721.commit-f7d0ae0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
913561
10424