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
12 changes: 10 additions & 2 deletions bend2/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,15 @@ async function cli_checkup(file: string): Promise<void> {
const base = await book_read(BASE);
let bad = false;
for (const raw of fs.readFileSync(file, "utf8").split("\n")) {
const line = raw.trim();
if (line === "" || line.startsWith("#")) {
continue;
}
if (!/^import(\s|$)/.test(line)) {
break;
}
const m = /^import\s+(\S+)\s+as\s+[A-Za-z_][A-Za-z0-9_]*\s*(?:#.*)?$/
.exec(raw.trim());
.exec(line);
if (m === null) {
continue;
}
Expand All @@ -343,7 +350,8 @@ async function cli_checkup(file: string): Promise<void> {
cli_say(1, "--- " + m[1] + " ---\n");
let code = 1;
try {
const own = /^import Base\s*(?:#.*)?$/m.test(fs.readFileSync(at, "utf8"));
const own = /^(?:[\t\r ]*(?:(?:#|import )[^\n]*)?\n)*[\t ]*import Base\s/
.test(fs.readFileSync(at, "utf8"));
code = book_run(await book_read(at, own ? base : undefined), [at]);
} catch (e) {
cli_say(2, book_err(e) + "\n");
Expand Down
20 changes: 20 additions & 0 deletions gates/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@ try {
check("guide, base and a program run through the executable",
guide.out.startsWith("# Bend") && base.out.startsWith("type Map")
&& sum5.code === 0 && sum5.out === "5n\n");
const header_source = path.join(TMP, "literal-checkup.bend");
fs.writeFileSync(header_source,
"# a header\nimport Base\n\nimport ./sum.bend as Sum\n"
+ "def text() -> String:\n \"body text\n"
+ "import ./absent.bend as Hidden\nmore text\"\n");
const header_check = await bend([header_source, "--check-only"],
{ BEND_NO_TELEMETRY: "1" });
const header_run = await bend([header_source, "--checkup"],
{ BEND_NO_TELEMETRY: "1" });
check("valid body literal text does not add an independent import",
header_check.code === 0 && header_run.code === 0
&& header_run.out.endsWith("5n\n"));
const no_base = path.join(TMP, "no-base.bend");
fs.writeFileSync(no_base,
"def main() -> String:\n \"body\nimport Base\n\"\n");
fs.writeFileSync(header_source, "import ./no-base.bend as NoBase\n");
const base_run = await bend([header_source, "--checkup"],
{ BEND_NO_TELEMETRY: "1" });
check("--checkup gives Base only to a module that imports it",
base_run.code === 1);
fs.writeFileSync(path.join(TMP, "page.html"),
"<script type=\"module\" src=\"./page.ts\"></script>\n");
fs.writeFileSync(path.join(TMP, "page.ts"), "import \"./none.ts\";\n");
Expand Down