zuzu-js 0.2.0 → 0.3.0

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.
package/lib/cli.js CHANGED
@@ -254,7 +254,7 @@ function stripShebang( source ) {
254
254
  }
255
255
 
256
256
  function printVersion( runtime, verbose ) {
257
- process.stdout.write( 'zuzu-js version 0.2.0\n' );
257
+ process.stdout.write( 'zuzu-js version 0.3.0\n' );
258
258
  if ( verbose ) {
259
259
  process.stdout.write( '\nlib search paths:\n' );
260
260
  for ( const p of runtime.getModuleSearchRoots() ) {
package/lib/runtime.js CHANGED
@@ -53,6 +53,28 @@ const textEncoder = new TextEncoder();
53
53
  const utf8Decoder = new TextDecoder( 'utf-8', { fatal: true } );
54
54
  const ZUZU_SKIP_BUILD = Symbol.for( 'zuzu.skip_build' );
55
55
 
56
+ const runtimeVersion = (() => {
57
+ if ( typeof globalThis === 'object' && globalThis !== null ) {
58
+ const globalVersion = globalThis.__ZUZU_RUNTIME_VERSION;
59
+ if ( typeof globalVersion === 'string' && globalVersion.trim() ) {
60
+ return String( globalVersion );
61
+ }
62
+ }
63
+ if ( typeof process === 'object' && process && process.versions ) {
64
+ try {
65
+ const packageMetadata = require( '../package.json' );
66
+ const packageVersion = packageMetadata && packageMetadata.version;
67
+ if ( packageVersion ) {
68
+ return String( packageVersion );
69
+ }
70
+ }
71
+ catch ( err ) {
72
+ return 'dev';
73
+ }
74
+ }
75
+ return 'dev';
76
+ })();
77
+
56
78
  function defaultModuleSearchRoots( host, repoRoot, includePaths ) {
57
79
  if ( host.name === 'browser' ) {
58
80
  return [
@@ -1283,7 +1305,11 @@ function defineZuzuClass( name, base, spec = {} ) {
1283
1305
  zuzuStoreField( this, field, value );
1284
1306
  }
1285
1307
  let named = null;
1286
- if ( ctorArgs.length === 1 && isPairListLike( ctorArgs[0] ) ) {
1308
+ const lastArg = ctorArgs[ctorArgs.length - 1];
1309
+ if (
1310
+ ctorArgs.length === 1
1311
+ && isPairListLike( ctorArgs[0] )
1312
+ ) {
1287
1313
  named = ctorArgs[0];
1288
1314
  }
1289
1315
  else if (
@@ -1294,6 +1320,20 @@ function defineZuzuClass( name, base, spec = {} ) {
1294
1320
  ) {
1295
1321
  named = ctorArgs[0];
1296
1322
  }
1323
+ else if (
1324
+ ctorArgs.length > 1
1325
+ && isPairListLike( lastArg )
1326
+ ) {
1327
+ named = lastArg;
1328
+ }
1329
+ else if (
1330
+ ctorArgs.length > 1
1331
+ && lastArg
1332
+ && typeof lastArg === 'object'
1333
+ && !Array.isArray( lastArg )
1334
+ ) {
1335
+ named = lastArg;
1336
+ }
1297
1337
  const releaseTemporaryNamed = !skipBuild
1298
1338
  && isPairListLike( named )
1299
1339
  && named.__zuzu_temporary_call_args === true;
@@ -1459,9 +1499,6 @@ function zuzuCallMember( object, property, ...args ) {
1459
1499
  if ( dictMethod ) {
1460
1500
  return dictMethod( ...args );
1461
1501
  }
1462
- if ( args.length === 0 ) {
1463
- return value;
1464
- }
1465
1502
  throw new TypeError( `${String( property )} is not a function` );
1466
1503
  }
1467
1504
 
@@ -2421,7 +2458,7 @@ class ZuzuScript {
2421
2458
  const systemGlobalSeed = {
2422
2459
  language_version: 0,
2423
2460
  runtime: 'zuzu-js',
2424
- runtime_version: 'dev',
2461
+ runtime_version: runtimeVersion,
2425
2462
  platform: this.host.name,
2426
2463
  inc: Object.freeze( moduleSearchRoots.slice() ),
2427
2464
  deny_fs: capabilityFlags.fs ? false : true,
@@ -609,6 +609,8 @@ function extractSpecialPreludeNames( signature ) {
609
609
  return [ '__zuzu_call_args', signature.headName, signature.restName, signature.namedName, '__i', '__a' ];
610
610
  case 'scalar_pairlist':
611
611
  return [ '__zuzu_call_args', signature.headName, signature.namedName, '__i', '__a' ];
612
+ case 'scalar_pairlist_array':
613
+ return [ '__zuzu_call_args', signature.headName, signature.namedName, signature.restName, '__i', '__a' ];
612
614
  case 'variadic':
613
615
  return [ '__zuzu_call_args', signature.headName, signature.restName, '__i', '__a' ];
614
616
  default:
@@ -694,6 +696,22 @@ function analyzeSpecialSignature( params ) {
694
696
  namedName: params[1].name,
695
697
  };
696
698
  }
699
+ if (
700
+ params.length === 3
701
+ && params[0].type === 'Parameter'
702
+ && params[1].type === 'SpecialParameter'
703
+ && params[1].special === 'rest_only'
704
+ && params[1].containerType === 'PairList'
705
+ && params[2].type === 'Parameter'
706
+ && ( params[2].typeName === 'Array' || params[2].typeName == null )
707
+ ) {
708
+ return {
709
+ kind: 'scalar_pairlist_array',
710
+ headName: params[0].name,
711
+ namedName: params[1].name,
712
+ restName: params[2].name,
713
+ };
714
+ }
697
715
  if (
698
716
  params.length === 1
699
717
  && params[0].type === 'SpecialParameter'
@@ -835,6 +853,19 @@ function emitSpecialFunctionPreamble( signature ) {
835
853
  '}',
836
854
  `const ${signature.namedName} = __zuzu_named_args;`,
837
855
  ].join( '\n' );
856
+ case 'scalar_pairlist_array':
857
+ return [
858
+ 'const __zuzu_call_args = Array.prototype.slice.call( arguments );',
859
+ `const ${signature.headName} = __zuzu_call_args[0];`,
860
+ 'let __zuzu_named_args = __zuzu_pairlist_literal( [] );',
861
+ 'const __zuzu_rest_args = [];',
862
+ 'for ( let __i = 1; __i < __zuzu_call_args.length; __i++ ) {',
863
+ 'const __a = __zuzu_call_args[__i];',
864
+ 'if ( __zuzu_is_pairlist( __a ) ) { __zuzu_named_args = __a; } else { __zuzu_rest_args.push( __a ); }',
865
+ '}',
866
+ `const ${signature.restName} = __zuzu_rest_args;`,
867
+ `const ${signature.namedName} = __zuzu_named_args;`,
868
+ ].join( '\n' );
838
869
  case 'variadic':
839
870
  return [
840
871
  'const __zuzu_call_args = Array.prototype.slice.call( arguments );',
@@ -2163,6 +2194,9 @@ function emitAssignmentExpression( node ) {
2163
2194
  : `${left} = __zuzu_assign_strong( ${left}, ${right} )`;
2164
2195
  }
2165
2196
  if ( node.left && node.left.type === 'MemberExpression' ) {
2197
+ if ( !node.left.computed ) {
2198
+ throw new UnsupportedSyntaxError( 'Invalid assignment target' );
2199
+ }
2166
2200
  const object = emitExpression( node.left.object );
2167
2201
  const objectTarget = emitAssignmentTarget( node.left.object );
2168
2202
  const key = node.left.computed
@@ -235,6 +235,7 @@ function validateExpression( node, scope ) {
235
235
  }
236
236
  return;
237
237
  case 'UpdateExpression':
238
+ requireValidAssignmentTarget( node.argument );
238
239
  if ( node.argument && node.argument.type === 'Identifier' ) {
239
240
  requireMutable( node.argument, scope );
240
241
  }
@@ -242,6 +243,23 @@ function validateExpression( node, scope ) {
242
243
  validateExpression( node.argument, scope );
243
244
  }
244
245
  return;
246
+ case 'UnaryExpression':
247
+ if ( node.operator === '++' || node.operator === '--' ) {
248
+ requireValidAssignmentTarget( node.argument );
249
+ if ( node.argument && node.argument.type === 'Identifier' ) {
250
+ requireMutable( node.argument, scope );
251
+ }
252
+ else {
253
+ validateExpression( node.argument, scope );
254
+ }
255
+ return;
256
+ }
257
+ validateChildNodes( node, scope );
258
+ return;
259
+ case 'RefExpression':
260
+ requireValidAssignmentTarget( node.argument );
261
+ validateExpression( node.argument, scope );
262
+ return;
245
263
  case 'FunctionExpression':
246
264
  validateFunctionBody( node, scope );
247
265
  return;
@@ -261,11 +279,13 @@ function requireValidAssignmentTarget( node ) {
261
279
  }
262
280
  if (
263
281
  target.type === 'Identifier'
264
- || target.type === 'MemberExpression'
265
282
  || target.type === 'SliceExpression'
266
283
  ) {
267
284
  return;
268
285
  }
286
+ if ( target.type === 'MemberExpression' && target.computed ) {
287
+ return;
288
+ }
269
289
  if (
270
290
  target.type === 'BinaryExpression'
271
291
  && [ '@', '@@', '@?' ].includes( target.operator )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuzu-js",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "JavaScript runtime, compiler, and browser bundle for ZuzuScript.",
5
5
  "main": "lib/zuzu.js",
6
6
  "bin": {