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.27.14
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.27.15
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Nov 2, 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
    0b8abe4 View commit details
Showing with 14 additions and 4 deletions.
  1. +1 −0 src/diagnosticMessages.json
  2. +7 −2 src/parser.ts
  3. +2 −0 tests/parser/namespace.ts
  4. +4 −2 tests/parser/namespace.ts.fixture.ts
1 change: 1 addition & 0 deletions src/diagnosticMessages.json
Original file line number Diff line number Diff line change
@@ -194,6 +194,7 @@
"Cannot extend a class '{0}'. Class constructor is marked as private.": 2675,
"The 'this' types of each signature are incompatible.": 2685,
"Namespace '{0}' has no exported member '{1}'.": 2694,
"Namespace can only have declarations.": 2695,
"Required type parameters may not follow optional type parameters.": 2706,
"Duplicate property '{0}'.": 2718,
"Property '{0}' is missing in type '{1}' but required in type '{2}'.": 2741,
9 changes: 7 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -398,9 +398,14 @@ export class Parser extends DiagnosticEmitter {
tn.range(declareStart, declareEnd), "declare"
); // recoverable
}
if (!namespace) {
if (namespace) {
this.error(
DiagnosticCode.Namespace_can_only_have_declarations,
tn.range(startPos)
);
} else {
statement = this.parseStatement(tn, true);
} // TODO: else?
}
}
break;
}
2 changes: 2 additions & 0 deletions tests/parser/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
let outerVar:i32 = 0;
declare namespace A {
namespace B {
export namespace C {
var aVar: i32;
outerVar = 42; // 2695: Namespace can only have declarations.
const aConst: i32;
const aConstInvalid: i32 = 0; // 1039: Initializers are not allowed in ambient contexts.
function aFunc(): void;
6 changes: 4 additions & 2 deletions tests/parser/namespace.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
let outerVar: i32 = 0;
declare namespace A {
namespace B {
export namespace C {
@@ -14,5 +15,6 @@ declare namespace A {
}
}
}
// ERROR 1039: "Initializers are not allowed in ambient contexts." in namespace.ts(6,32+1)
// ERROR 1183: "An implementation cannot be declared in ambient contexts." in namespace.ts(8,37+1)
// ERROR 2695: "Namespace can only have declarations." in namespace.ts(6,7+0)
// ERROR 1039: "Initializers are not allowed in ambient contexts." in namespace.ts(8,32+1)
// ERROR 1183: "An implementation cannot be declared in ambient contexts." in namespace.ts(10,37+1)