mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add more inputs
This commit is contained in:
11
inputs/failing/captureBeforeInit.ts
Normal file
11
inputs/failing/captureBeforeInit.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function() {
|
||||
let res = foo(); // Should fail compilation: Binds uninitialized variable
|
||||
|
||||
let x = 3;
|
||||
|
||||
function foo() {
|
||||
return x;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
10
inputs/failing/captureMutated.ts
Normal file
10
inputs/failing/captureMutated.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export default function() {
|
||||
let x = 0;
|
||||
x++;
|
||||
|
||||
function foo() {
|
||||
return x; // Should fail compilation due to capture on line 3
|
||||
}
|
||||
|
||||
return foo();
|
||||
}
|
||||
14
inputs/failing/captureShadowed.ts
Normal file
14
inputs/failing/captureShadowed.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export default function() {
|
||||
function foo() {
|
||||
const x = 3;
|
||||
return x + bar();
|
||||
}
|
||||
|
||||
const x = 4;
|
||||
|
||||
function bar() {
|
||||
return x;
|
||||
}
|
||||
|
||||
return foo();
|
||||
}
|
||||
5
inputs/failing/const.ts
Normal file
5
inputs/failing/const.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export default function() {
|
||||
const foo = 0;
|
||||
foo++; // Should throw
|
||||
return foo;
|
||||
}
|
||||
10
inputs/failing/mutateCaptured.ts
Normal file
10
inputs/failing/mutateCaptured.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export default function() {
|
||||
let x = 0;
|
||||
|
||||
function foo() {
|
||||
x++; // Should fail compilation: mutates captures variable
|
||||
return x;
|
||||
}
|
||||
|
||||
return foo();
|
||||
}
|
||||
5
inputs/failing/temporalDeadZone.ts
Normal file
5
inputs/failing/temporalDeadZone.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export default function() {
|
||||
let result = foo;
|
||||
let foo = 'oops';
|
||||
return result; // should throw
|
||||
}
|
||||
14
inputs/passing/shadow.ts
Normal file
14
inputs/passing/shadow.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export default function() {
|
||||
let sum = 0;
|
||||
|
||||
const x = 1;
|
||||
|
||||
{
|
||||
const x = 2;
|
||||
sum += x;
|
||||
}
|
||||
|
||||
sum += x;
|
||||
|
||||
return sum; // 3 (not 4)
|
||||
}
|
||||
13
inputs/passing/transitiveCapture.ts
Normal file
13
inputs/passing/transitiveCapture.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export default function() {
|
||||
const x = 3;
|
||||
|
||||
function foo() {
|
||||
return bar();
|
||||
}
|
||||
|
||||
function bar() {
|
||||
return x;
|
||||
}
|
||||
|
||||
return foo();
|
||||
}
|
||||
Reference in New Issue
Block a user