porffor 0.30.1 → 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1800,6 +1800,13 @@ const disposeLeftover = wasm => {
1800
1800
  const generateExp = (scope, decl) => {
1801
1801
  const expression = decl.expression;
1802
1802
 
1803
+ if (expression.type === 'Literal' && typeof expression.value === 'string') {
1804
+ if (expression.value === 'use strict') {
1805
+ scope.strict = true;
1806
+ }
1807
+ return [];
1808
+ }
1809
+
1803
1810
  const out = generate(scope, expression, undefined, undefined, Prefs.optUnused);
1804
1811
  disposeLeftover(out);
1805
1812
 
@@ -3607,10 +3614,8 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3607
3614
  }
3608
3615
 
3609
3616
  if (local === undefined) {
3610
- // todo: this should be a sloppy mode only thing
3611
-
3612
- // only allow = for this
3613
- if (op !== '=') return internalThrow(scope, 'ReferenceError', `${unhackName(name)} is not defined`);
3617
+ // only allow = for this, or if in strict mode always throw
3618
+ if (op !== '=' || scope.strict) return internalThrow(scope, 'ReferenceError', `${unhackName(name)} is not defined`, true);
3614
3619
 
3615
3620
  if (type != 'Identifier') {
3616
3621
  const tmpName = '#rhs' + uniqId();
@@ -3623,6 +3628,8 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3623
3628
  }
3624
3629
 
3625
3630
  if (Object.hasOwn(builtinVars, name)) {
3631
+ if (scope.strict) return internalThrow(scope, 'TypeError', `Cannot assign to non-writable global ${name}`, true);
3632
+
3626
3633
  // just return rhs (eg `NaN = 2`)
3627
3634
  return generate(scope, decl.right);
3628
3635
  }
@@ -3749,7 +3756,6 @@ const generateUnary = (scope, decl) => {
3749
3756
 
3750
3757
  // if ReferenceError (undeclared var), ignore and return true. otherwise false
3751
3758
  if (!out[1]) {
3752
- // todo: throw in strict mode
3753
3759
  // exists
3754
3760
  toReturn = false;
3755
3761
  } else {
@@ -4022,7 +4028,7 @@ const generateForOf = (scope, decl) => {
4022
4028
  // setup local for left
4023
4029
  let setVar;
4024
4030
  if (decl.left.type === 'Identifier') {
4025
- // todo: should be sloppy mode only
4031
+ if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
4026
4032
  setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
4027
4033
  } else {
4028
4034
  // todo: verify this is correct
@@ -4389,7 +4395,7 @@ const generateForIn = (scope, decl) => {
4389
4395
 
4390
4396
  let setVar;
4391
4397
  if (decl.left.type === 'Identifier') {
4392
- // todo: should be sloppy mode only
4398
+ if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
4393
4399
  setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
4394
4400
  } else {
4395
4401
  // todo: verify this is correct
@@ -5638,7 +5644,8 @@ const generateFunc = (scope, decl) => {
5638
5644
  // not arrow function or main
5639
5645
  (decl.type && decl.type !== 'ArrowFunctionExpression' && decl.type !== 'Program') &&
5640
5646
  // not async or generator
5641
- !decl.async && !decl.generator
5647
+ !decl.async && !decl.generator,
5648
+ strict: scope.strict
5642
5649
  };
5643
5650
 
5644
5651
  funcIndex[name] = func.index;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.30.1+616eeaaf5",
4
+ "version": "0.30.2+2e9f2148f",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.30.1+616eeaaf5';
3
+ globalThis.version = '0.30.2+2e9f2148f';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -115,7 +115,10 @@ if (process.argv.length >= 4) {
115
115
  if (evalIndex !== -1) {
116
116
  source = process.argv[evalIndex + 1];
117
117
  if (source) {
118
- if (source.startsWith('"') || source.startsWith("'")) source = source.slice(1, -1);
118
+ // todo: this isn't entirely right, because shells should do the quoting for us but works well enough, see below as well
119
+ if ((source.startsWith('"') || source.startsWith("'")) && (source.endsWith('"') || source.endsWith("'"))) {
120
+ source = source.slice(1, -1);
121
+ }
119
122
  process.argv.splice(evalIndex, 2); // remove flag and value
120
123
  }
121
124
  }
@@ -126,7 +129,9 @@ if (process.argv.length >= 4) {
126
129
  process.argv.push('--no-opt-unused');
127
130
  source = process.argv[printIndex + 1];
128
131
  if (source) {
129
- if (source.startsWith('"') || source.startsWith("'")) source = source.slice(1, -1);
132
+ if ((source.startsWith('"') || source.startsWith("'")) && (source.endsWith('"') || source.endsWith("'"))) {
133
+ source = source.slice(1, -1);
134
+ }
130
135
  process.argv.splice(printIndex, 2); // remove flag and value
131
136
  }
132
137