Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AssemblyScript/assemblyscript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.26.0
Choose a base ref
...
head repository: AssemblyScript/assemblyscript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.26.1
Choose a head ref
  • 3 commits
  • 5 files changed
  • 3 contributors

Commits on Jan 8, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    282d924 View commit details
  2. Copy the full SHA
    c9297db View commit details
  3. Copy the full SHA
    d46bfeb View commit details
Showing with 619 additions and 560 deletions.
  1. +16 −4 src/parser.ts
  2. +6 −0 src/program.ts
  3. +556 −556 std/assembly/util/math.ts
  4. +19 −0 tests/parser/asi.ts
  5. +22 −0 tests/parser/asi.ts.fixture.ts
20 changes: 16 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -939,7 +939,7 @@ export class Parser extends DiagnosticEmitter {
} while (tn.skip(Token.Comma));

let ret = Node.createVariableStatement(decorators, declarations, tn.range(startPos, tn.pos));
tn.skip(Token.Semicolon);
if (!tn.skip(Token.Semicolon) && !isFor) this.checkASI(tn);
return ret;
}

@@ -1122,7 +1122,7 @@ export class Parser extends DiagnosticEmitter {
}

let ret = Node.createReturnStatement(expr, tn.range(startPos, tn.pos));
tn.skip(Token.Semicolon);
if (!tn.skip(Token.Semicolon)) this.checkASI(tn);
return ret;
}

@@ -3009,7 +3009,7 @@ export class Parser extends DiagnosticEmitter {
}
}
let ret = Node.createBlockStatement(statements, tn.range(startPos, tn.pos));
tn.skip(Token.Semicolon);
if (topLevel) tn.skip(Token.Semicolon);
return ret;
}

@@ -3417,7 +3417,7 @@ export class Parser extends DiagnosticEmitter {
let expression = this.parseExpression(tn);
if (!expression) return null;
let ret = Node.createThrowStatement(expression, tn.range(startPos, tn.pos));
tn.skip(Token.Semicolon);
if (!tn.skip(Token.Semicolon)) this.checkASI(tn);
return ret;
}

@@ -4401,6 +4401,18 @@ export class Parser extends DiagnosticEmitter {
return expr;
}

private checkASI(
tn: Tokenizer
): void {
// see: https://tc39.es/ecma262/#sec-automatic-semicolon-insertion
let token = tn.peek(true);
if (tn.nextTokenOnNewLine || token == Token.EndOfFile || token == Token.CloseBrace) return;
this.error(
DiagnosticCode.Unexpected_token,
tn.range(tn.nextTokenPos)
);
}

/** Skips over a statement on errors in an attempt to reduce unnecessary diagnostic noise. */
skipStatement(tn: Tokenizer): void {
tn.peek(true);
6 changes: 6 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
@@ -1501,6 +1501,7 @@ export class Program extends DiagnosticEmitter {
let thisInstanceMembers = thisPrototype.instanceMembers;
if (thisInstanceMembers) {
let thisMembers = Map_values(thisInstanceMembers);
let seen: Set<ClassPrototype> | null = null;
do {
let baseInstanceMembers = basePrototype.instanceMembers;
if (baseInstanceMembers) {
@@ -1525,6 +1526,11 @@ export class Program extends DiagnosticEmitter {
}
let nextPrototype = basePrototype.basePrototype;
if (!nextPrototype) break;
// Break on circular inheritance. Is diagnosed later, when resolved.
if (!seen) seen = new Set();
seen.add(basePrototype);
if (seen.has(nextPrototype)) break;
// Otherwise traverse to next base prototype.
basePrototype = nextPrototype;
} while (true);
}
1,112 changes: 556 additions & 556 deletions std/assembly/util/math.ts

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/parser/asi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function failLet(y: i32): i32 {
let x = y 234;
return x + y;
}

function failReturn(): i32 {
return 123 456;
}

function failThrow(): i32 {
throw 123 456;
}

function successCloseBrace(): i32 {
return 123 }

function successCloseParen(): i32 {
return ( 123 )
}
22 changes: 22 additions & 0 deletions tests/parser/asi.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function failLet(y: i32): i32 {
let x = y;
234;
return x + y;
}
function failReturn(): i32 {
return 123;
456;
}
function failThrow(): i32 {
throw 123;
456;
}
function successCloseBrace(): i32 {
return 123;
}
function successCloseParen(): i32 {
return (123);
}
// ERROR 1012: "Unexpected token." in asi.ts(2,13+0)
// ERROR 1012: "Unexpected token." in asi.ts(7,14+0)
// ERROR 1012: "Unexpected token." in asi.ts(11,13+0)