@poe-platform/safe-js 0.1.477 → 0.1.479

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.
@@ -2937,6 +2937,7 @@ function allHexDigits(value) {
2937
2937
  // packages/safe-js/src/parse/parser.ts
2938
2938
  var MAX_CONDITIONAL_EXPRESSION_DEPTH = 256;
2939
2939
  var MAX_IF_STATEMENT_DEPTH = 2048;
2940
+ var STRICT_BINDING_NAMES = /* @__PURE__ */ new Set(["eval", "arguments", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"]);
2940
2941
  var DisallowedSyntaxError = class extends Error {
2941
2942
  constructor(syntax, position) {
2942
2943
  super(`Disallowed syntax '${syntax}' at line ${position.line}, column ${position.column}.`);
@@ -3057,12 +3058,13 @@ var ordinaryFunctionContext = {
3057
3058
  await: true
3058
3059
  };
3059
3060
  var Parser = class {
3060
- constructor(tokens, source, compilation, functionContext = "top-level", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }) {
3061
+ constructor(tokens, source, compilation, functionContext = "top-level", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }, allowImportMeta = true) {
3061
3062
  this.tokens = tokens;
3062
3063
  this.source = source;
3063
3064
  this.compilation = compilation;
3064
3065
  this.functionContext = functionContext;
3065
3066
  this.lexicalContext = lexicalContext;
3067
+ this.allowImportMeta = allowImportMeta;
3066
3068
  this.functionScopes.add(this.scopes[0]);
3067
3069
  }
3068
3070
  tokens;
@@ -3070,6 +3072,7 @@ var Parser = class {
3070
3072
  compilation;
3071
3073
  functionContext;
3072
3074
  lexicalContext;
3075
+ allowImportMeta;
3073
3076
  index = 0;
3074
3077
  breakableDepth = 0;
3075
3078
  conditionalExpressionDepth = 0;
@@ -3088,6 +3091,19 @@ var Parser = class {
3088
3091
  });
3089
3092
  return node;
3090
3093
  }
3094
+ parseDynamicParameters() {
3095
+ this.parseArrowParameters();
3096
+ this.expectEof();
3097
+ }
3098
+ parseDynamicBody() {
3099
+ this.parseBlockStatement([]);
3100
+ this.expectEof();
3101
+ }
3102
+ parseDynamicExpression() {
3103
+ const node = this.parseFunctionExpression();
3104
+ this.expectEof();
3105
+ return node;
3106
+ }
3091
3107
  parseTopLevel() {
3092
3108
  if (this.isExportToken(this.currentToken())) {
3093
3109
  throw new DisallowedSyntaxError("export", this.currentToken().start);
@@ -3201,7 +3217,10 @@ var Parser = class {
3201
3217
  if (this.isAsyncArrowWithParenthesizedParams()) {
3202
3218
  const asyncToken = this.currentToken();
3203
3219
  this.index += 1;
3204
- const params = this.parseArrowParameters();
3220
+ const params = this.withLexicalContext({
3221
+ ...this.lexicalContext,
3222
+ ...this.lexicalContext.grammar === void 0 ? {} : { grammar: { ...this.lexicalContext.grammar, await: true } }
3223
+ }, () => this.parseArrowParameters());
3205
3224
  return this.finishArrowFunctionExpression(asyncToken.start, true, params);
3206
3225
  }
3207
3226
  if (this.isAsyncArrowWithSingleParam()) {
@@ -3231,7 +3250,8 @@ var Parser = class {
3231
3250
  const body = this.withLexicalContext({
3232
3251
  ...this.lexicalContext,
3233
3252
  return: true,
3234
- await: isAsync || this.lexicalContext.strictAwait !== true
3253
+ await: isAsync || this.lexicalContext.strictAwait !== true,
3254
+ ...this.lexicalContext.grammar === void 0 ? {} : { grammar: { ...this.lexicalContext.grammar, await: isAsync, yield: false } }
3235
3255
  }, () => this.parseArrowFunctionBody(params, isAsync));
3236
3256
  return this.withFunctionSource({
3237
3257
  type: "ArrowFunctionExpression",
@@ -3278,11 +3298,12 @@ var Parser = class {
3278
3298
  }
3279
3299
  return this.withFunctionContext(async ? "async" : "normal", () => this.parseExpression().node);
3280
3300
  }
3281
- parseBlockStatement(params, catchParam) {
3301
+ parseBlockStatement(params, catchParam, allowDuplicateParameters = false) {
3282
3302
  const start = this.expectPunctuator("{");
3283
3303
  return this.withScope(() => {
3284
3304
  for (const param of params ?? []) {
3285
3305
  for (const identifier of boundIdentifiers(param)) {
3306
+ if (allowDuplicateParameters && this.scopes[this.scopes.length - 1]?.has(identifier.name)) continue;
3286
3307
  this.declareBinding(identifier, "parameter");
3287
3308
  }
3288
3309
  }
@@ -3292,7 +3313,15 @@ var Parser = class {
3292
3313
  }
3293
3314
  }
3294
3315
  let directiveTokenIndex = this.index;
3295
- const body = this.parseBlockStatementBody(start);
3316
+ const body = this.parseBlockStatementBody(start, params !== void 0);
3317
+ if (params !== void 0 && this.lexicalContext.grammar?.strict) {
3318
+ const names = /* @__PURE__ */ new Set();
3319
+ for (const param of params) for (const identifier of boundIdentifiers(param)) {
3320
+ if (names.has(identifier.name) || STRICT_BINDING_NAMES.has(identifier.name))
3321
+ throw new Error(`Invalid strict function parameter '${identifier.name}'.`);
3322
+ names.add(identifier.name);
3323
+ }
3324
+ }
3296
3325
  if (params?.some((param) => param.type !== "Identifier")) {
3297
3326
  for (const statement of body.body) {
3298
3327
  const token = this.tokens[directiveTokenIndex];
@@ -3307,18 +3336,26 @@ var Parser = class {
3307
3336
  return body;
3308
3337
  }, params !== void 0);
3309
3338
  }
3310
- parseBlockStatementBody(start) {
3339
+ parseBlockStatementBody(start, functionBody = false) {
3311
3340
  const body = [];
3341
+ let directivePrologue = functionBody;
3312
3342
  while (this.consumePunctuator("}") === void 0) {
3313
3343
  if (this.currentToken().type === "eof") {
3314
3344
  throw new Error(
3315
3345
  `Unterminated block at line ${start.start.line}, column ${start.start.column}.`
3316
3346
  );
3317
3347
  }
3348
+ const firstToken = this.currentToken();
3318
3349
  const statement = this.parseStatement();
3319
3350
  body.push(statement);
3351
+ if (directivePrologue && this.lexicalContext.grammar !== void 0) {
3352
+ directivePrologue = statement.type === "ExpressionStatement" && statement.expression.type === "StringLiteral" && firstToken.type === "string" && statement.span.start.offset === firstToken.start.offset && statement.span.end.offset === firstToken.end.offset;
3353
+ if (directivePrologue && statement.type === "ExpressionStatement" && statement.expression.type === "StringLiteral" && (statement.expression.raw === '"use strict"' || statement.expression.raw === "'use strict'"))
3354
+ this.lexicalContext.grammar.strict = true;
3355
+ }
3356
+ let semicolons = 0;
3320
3357
  while (statement.type !== "EmptyStatement" && this.consumePunctuator(";") !== void 0) {
3321
- continue;
3358
+ if (++semicolons > 1) directivePrologue = false;
3322
3359
  }
3323
3360
  }
3324
3361
  return {
@@ -3328,6 +3365,15 @@ var Parser = class {
3328
3365
  };
3329
3366
  }
3330
3367
  parseStatement(allowResourceDeclaration = true) {
3368
+ const statement = this.parseStatementBody(allowResourceDeclaration);
3369
+ if (this.lexicalContext.grammar !== void 0 && ["ExpressionStatement", "ReturnStatement", "ThrowStatement", "VariableDeclaration", "BreakStatement", "ContinueStatement"].includes(statement.type)) {
3370
+ const next = this.currentToken();
3371
+ if (next.type !== "eof" && next.value !== ";" && next.value !== "}" && next.start.line === statement.span.end.line)
3372
+ throw unexpectedTokenError(next);
3373
+ }
3374
+ return statement;
3375
+ }
3376
+ parseStatementBody(allowResourceDeclaration) {
3331
3377
  const emptyStatement = this.parseEmptyStatement();
3332
3378
  if (emptyStatement !== void 0) {
3333
3379
  return emptyStatement;
@@ -3945,6 +3991,12 @@ var Parser = class {
3945
3991
  });
3946
3992
  }
3947
3993
  parseClass(declaration) {
3994
+ return this.withLexicalContext({
3995
+ ...this.lexicalContext,
3996
+ ...this.lexicalContext.grammar === void 0 ? {} : { grammar: { ...this.lexicalContext.grammar, strict: true } }
3997
+ }, () => this.parseClassBody(declaration));
3998
+ }
3999
+ parseClassBody(declaration) {
3948
4000
  const start = this.expectKeyword("class");
3949
4001
  const id = isIdentifierLikeToken(this.currentToken()) && this.currentToken().value !== "extends" ? this.parseBindingIdentifier() : void 0;
3950
4002
  if (declaration && id === void 0) throw unexpectedTokenError(this.currentToken());
@@ -3980,18 +4032,30 @@ var Parser = class {
3980
4032
  });
3981
4033
  }
3982
4034
  parseFunctionParts(generator, lexicalContext, accessor, async = false) {
4035
+ const inheritedGrammar = this.lexicalContext.grammar;
4036
+ if (inheritedGrammar !== void 0) lexicalContext = {
4037
+ ...lexicalContext,
4038
+ grammar: { await: async, yield: generator, strict: inheritedGrammar.strict }
4039
+ };
3983
4040
  return this.withLexicalContext(lexicalContext, () => {
4041
+ let allowDuplicateParameters = false;
3984
4042
  const params = this.withScope(() => {
3985
4043
  const parsed = this.parseArrowParameters();
4044
+ allowDuplicateParameters = lexicalContext.grammar !== void 0 && !lexicalContext.grammar.strict && !lexicalContext.superProperty && parsed.every((param) => param.type === "Identifier");
4045
+ const names = /* @__PURE__ */ new Set();
3986
4046
  for (const param of parsed)
3987
- for (const identifier of boundIdentifiers(param)) this.declareBinding(identifier);
4047
+ for (const identifier of boundIdentifiers(param)) {
4048
+ if (allowDuplicateParameters && names.has(identifier.name)) continue;
4049
+ this.declareBinding(identifier);
4050
+ names.add(identifier.name);
4051
+ }
3988
4052
  return parsed;
3989
4053
  });
3990
4054
  if (accessor === "get" && params.length !== 0)
3991
4055
  throw new Error("A getter cannot have parameters.");
3992
4056
  if (accessor === "set" && (params.length !== 1 || params[0]?.type === "RestElement"))
3993
4057
  throw new Error("A setter must have exactly one non-rest parameter.");
3994
- const body = this.withFunctionContext(generator ? async ? "async-generator" : "generator" : async ? "async" : "normal", () => this.parseBlockStatement(params));
4058
+ const body = this.withFunctionContext(generator ? async ? "async-generator" : "generator" : async ? "async" : "normal", () => this.parseBlockStatement(params, void 0, allowDuplicateParameters));
3995
4059
  return { params, body };
3996
4060
  });
3997
4061
  }
@@ -4158,7 +4222,7 @@ var Parser = class {
4158
4222
  }
4159
4223
  parseBindingTarget() {
4160
4224
  const token = this.currentToken();
4161
- if (isIdentifierLikeToken(token)) {
4225
+ if (isIdentifierLikeToken(token) || this.isContextualIdentifier(token)) {
4162
4226
  return this.parseBindingIdentifier();
4163
4227
  }
4164
4228
  if (token.type === "punctuator" && token.value === "[") {
@@ -4171,12 +4235,18 @@ var Parser = class {
4171
4235
  }
4172
4236
  parseBindingIdentifier() {
4173
4237
  const token = this.currentToken();
4174
- if (!isIdentifierLikeToken(token)) {
4238
+ if (this.lexicalContext.grammar?.strict && STRICT_BINDING_NAMES.has(token.value))
4239
+ throw unexpectedTokenError(token);
4240
+ if (!isIdentifierLikeToken(token) && !this.isContextualIdentifier(token)) {
4175
4241
  throw unexpectedTokenError(token);
4176
4242
  }
4177
4243
  this.index += 1;
4178
4244
  return createIdentifier2(token);
4179
4245
  }
4246
+ isContextualIdentifier(token) {
4247
+ const grammar = this.lexicalContext.grammar;
4248
+ return grammar !== void 0 && token.type === "keyword" && (token.value === "await" && !grammar.await || token.value === "yield" && !grammar.yield && !grammar.strict);
4249
+ }
4180
4250
  parseArrayPattern() {
4181
4251
  const start = this.expectPunctuator("[");
4182
4252
  const elements = [];
@@ -4700,7 +4770,7 @@ var Parser = class {
4700
4770
  parenthesized: false
4701
4771
  };
4702
4772
  }
4703
- if (token.type === "keyword" && token.value === "yield") {
4773
+ if (token.type === "keyword" && token.value === "yield" && !this.isContextualIdentifier(token)) {
4704
4774
  if (this.functionContext !== "generator" && this.functionContext !== "async-generator") {
4705
4775
  throw new Error(
4706
4776
  `yield is only valid inside a generator body at line ${token.start.line}, column ${token.start.column}.`
@@ -4727,7 +4797,7 @@ var Parser = class {
4727
4797
  parenthesized: false
4728
4798
  };
4729
4799
  }
4730
- if (token.type === "keyword" && token.value === "await") {
4800
+ if (token.type === "keyword" && token.value === "await" && !this.isContextualIdentifier(token)) {
4731
4801
  if (!this.lexicalContext.await) throw new DisallowedSyntaxError("await in a class element", token.start);
4732
4802
  if (this.functionContext === "generator") {
4733
4803
  throw new Error(
@@ -4933,7 +5003,7 @@ var Parser = class {
4933
5003
  if (isNewToken(token)) {
4934
5004
  return this.parseNewExpression();
4935
5005
  }
4936
- if (isIdentifierLikeToken(token)) {
5006
+ if (isIdentifierLikeToken(token) || this.isContextualIdentifier(token)) {
4937
5007
  assertAllowedIdentifierReference(token);
4938
5008
  this.index += 1;
4939
5009
  return {
@@ -5788,6 +5858,8 @@ var Parser = class {
5788
5858
  }
5789
5859
  withLexicalContext(context, callback) {
5790
5860
  const previous = this.lexicalContext;
5861
+ if (context.grammar === void 0 && previous.grammar !== void 0)
5862
+ context = { ...context, grammar: { ...previous.grammar } };
5791
5863
  this.lexicalContext = context;
5792
5864
  try {
5793
5865
  return callback();
@@ -5927,6 +5999,7 @@ var Parser = class {
5927
5999
  }
5928
6000
  parseImportMeta() {
5929
6001
  const importToken = this.currentToken();
6002
+ if (!this.allowImportMeta) throw new Error("import.meta is only valid in module source.");
5930
6003
  if (!this.isImportMetaStart()) {
5931
6004
  throw unexpectedTokenError(importToken);
5932
6005
  }
@@ -57191,4 +57264,4 @@ authorization of the copyright holder.
57191
57264
  SPDX-License-Identifier: Unicode-3.0
57192
57265
 
57193
57266
  */
57194
- //# sourceMappingURL=chunk-7VEKZ6RN.js.map
57267
+ //# sourceMappingURL=chunk-OBSLXRJL.js.map