Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 102 additions & 196 deletions cli/asc.js

Large diffs are not rendered by default.

47 changes: 12 additions & 35 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,19 +683,12 @@ export abstract class Node {
if (path) {
let normalizedPath = normalizePath(path.value);
if (path.value.startsWith(".")) { // relative
stmt.normalizedPath = resolvePath(
normalizedPath,
range.source.normalizedPath
);
normalizedPath = resolvePath(normalizedPath, range.source.internalPath);
} else { // absolute
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) {
normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.normalizedPath = normalizedPath;
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
stmt.internalPath = mangleInternalPath(normalizedPath);
} else {
stmt.normalizedPath = null;
stmt.internalPath = null;
}
stmt.isDeclare = isDeclare;
Expand Down Expand Up @@ -772,17 +765,11 @@ export abstract class Node {
stmt.path = path;
var normalizedPath = normalizePath(path.value);
if (path.value.startsWith(".")) { // relative in project
stmt.normalizedPath = resolvePath(
normalizedPath,
range.source.normalizedPath
);
normalizedPath = resolvePath(normalizedPath, range.source.internalPath);
} else { // absolute in library
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) {
normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.normalizedPath = normalizedPath;
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
stmt.internalPath = mangleInternalPath(normalizedPath);
return stmt;
}

Expand All @@ -798,17 +785,11 @@ export abstract class Node {
stmt.path = path;
var normalizedPath = normalizePath(path.value);
if (path.value.startsWith(".")) {
stmt.normalizedPath = resolvePath(
normalizedPath,
range.source.normalizedPath
);
normalizedPath = resolvePath(normalizedPath, range.source.internalPath);
} else {
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) {
normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.normalizedPath = normalizedPath;
if (!normalizedPath.startsWith(LIBRARY_PREFIX)) normalizedPath = LIBRARY_PREFIX + normalizedPath;
}
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
stmt.internalPath = mangleInternalPath(normalizedPath);
return stmt;
}

Expand Down Expand Up @@ -1636,7 +1617,7 @@ export class Source extends Node {

/** Source kind. */
sourceKind: SourceKind;
/** Normalized path. */
/** Normalized path with file extension. */
normalizedPath: string;
/** Path used internally. */
internalPath: string;
Expand Down Expand Up @@ -1812,9 +1793,7 @@ export class ExportStatement extends Statement {
members: ExportMember[] | null;
/** Path being exported from, if applicable. */
path: StringLiteralExpression | null;
/** Normalized path, if `path` is set. */
normalizedPath: string | null;
/** Mangled internal path being referenced, if `path` is set. */
/** Internal path being referenced, if `path` is set. */
internalPath: string | null;
/** Whether this is a declared export. */
isDeclare: bool;
Expand Down Expand Up @@ -1934,9 +1913,7 @@ export class ImportStatement extends Statement {
namespaceName: IdentifierExpression | null;
/** Path being imported from. */
path: StringLiteralExpression;
/** Normalized path. */
normalizedPath: string;
/** Mangled internal path being referenced. */
/** Internal path being referenced. */
internalPath: string;
}

Expand Down
6 changes: 3 additions & 3 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1663,17 +1663,17 @@ export class Compiler extends DiagnosticEmitter {
break;
}
case NodeKind.EXPORT: {
if ((<ExportStatement>statement).normalizedPath != null) {
if ((<ExportStatement>statement).internalPath != null) {
this.compileFileByPath(
<string>(<ExportStatement>statement).normalizedPath,
<string>(<ExportStatement>statement).internalPath,
<StringLiteralExpression>(<ExportStatement>statement).path
);
}
break;
}
case NodeKind.IMPORT: {
this.compileFileByPath(
(<ImportStatement>statement).normalizedPath,
(<ImportStatement>statement).internalPath,
(<ImportStatement>statement).path
);
break;
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import { Parser } from "./parser";
import { Program } from "./program";

/** Parses a source file. If `parser` has been omitted a new one is created. */
export function parseFile(text: string, path: string, isEntry: bool = false,
export function parseFile(
/** Source text of the file. */
text: string,
/** Normalized path of the file. */
path: string,
/** Whether this is an entry file. */
isEntry: bool = false,
/** Parser reference. */
parser: Parser | null = null
): Parser {
if (!parser) parser = new Parser();
Expand Down Expand Up @@ -154,6 +161,11 @@ export function finishParsing(parser: Parser): Program {
return parser.finish();
}

/** Obtains the source of the given file. */
export function getSource(program: Program, internalPath: string): string | null {
return program.getSource(internalPath);
}

/** Compiles the sources computed by the parser to a module. */
export function compileProgram(program: Program, options: Options | null = null): Module {
return new Compiler(program, options).compile();
Expand Down
10 changes: 6 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ export class Parser extends DiagnosticEmitter {

/** Parses a file and adds its definitions to the program. */
parseFile(
/** Source text of the file. */
text: string,
/** Normalized path of the file. */
path: string,
/** Whether this is an entry file. */
isEntry: bool
): void {
// the frontend gives us paths with .ts endings
var normalizedPath = normalizePath(path);
var internalPath = mangleInternalPath(normalizedPath);
// check if already processed
Expand Down Expand Up @@ -379,12 +383,10 @@ export class Parser extends DiagnosticEmitter {
return backlog.length ? backlog.shift() : null;
}

/** Obtains the dependee for a given import */
/** Obtains the dependee of the given imported file. */
getDependee(dependent: string): string | null {
var source = this.dependees.get(dependent);
if (source) {
return source.internalPath;
}
if (source) return source.internalPath;
return null;
}

Expand Down
10 changes: 10 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ export class Program extends DiagnosticEmitter {
this.resolver = new Resolver(this);
}

/** Obtains the source matching the specified internal path. */
getSource(internalPath: string): string | null {
var sources = this.sources;
for (let i = 0; i < sources.length; ++i) {
let source = sources[i];
if (source.internalPath == internalPath) return source.text;
}
return null;
}

/** Writes a common runtime header to the specified buffer. */
writeRuntimeHeader(buffer: Uint8Array, offset: i32, classInstance: Class, payloadSize: u32): void {
// BLOCK {
Expand Down
5 changes: 3 additions & 2 deletions tests/packages/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"scripts": {
"test": "npm run a && npm run b && npm run c && npm run d && npm run e && npm run f && npm run g && npm run as",
"test": "npm run a && npm run b && npm run c && npm run d && npm run e && npm run f && npm run g && npm run as && npm run h",
"a": "cd ./packages/a && node ../../../../bin/asc assembly/index.ts --noEmit --runtime stub --validate",
"as": "cd ./packages/as && node ../../../../bin/asc as/index.ts --noEmit --runtime stub --validate",
"b": "cd ./packages/b && node ../../../../bin/asc assembly/index.ts --noEmit --runtime stub && node ../../../../bin/asc assembly/index.ts --noEmit --runtime stub --listFiles",
"c": "cd ./packages/c && node ../../../../bin/asc assembly/index.ts --noEmit --runtime stub --validate",
"d": "cd ./packages/d && node ../../../../bin/asc assembly/index.ts --path packages --noEmit --runtime stub --validate --traceResolution",
"e": "cd ./packages/d/packages/e && node ../../../../../../bin/asc assembly/index.ts --noEmit --runtime stub --validate",
"f": "cd ./packages/d/packages/e/packages/f && node ../../../../../../../../bin/asc assembly/index.ts --noEmit --runtime stub --validate",
"g": "cd ./packages/g && node test.js"
"g": "cd ./packages/g && node test.js",
"h": "cd ./packages/h && node ../../../../bin/asc assembly/index.ts --noEmit --runtime none --validate --traceResolution"
},
"author": "Willem Wyndham",
"license": "Apache-2.0"
Expand Down
3 changes: 3 additions & 0 deletions tests/packages/packages/d/node_modules/as/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/packages/packages/g/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ let asc = require("../../../../cli/asc");
let argv = [
"assembly/index.ts",
"--noEmit",
"--runtime",
"stub",
"--runtime", "stub",
"--validate",
"--traceResolution"
];
Expand Down
5 changes: 5 additions & 0 deletions tests/packages/packages/h/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { h } from "@foo/bar";

export function getH(): i32 {
return h;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.