@danielx/civet 0.6.5 → 0.6.6

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/dist/browser.js CHANGED
@@ -2463,6 +2463,7 @@ var Civet = (() => {
2463
2463
  literalValue,
2464
2464
  makeAsConst,
2465
2465
  makeLeftHandSideExpression,
2466
+ maybeRef,
2466
2467
  modifyString,
2467
2468
  needsRef,
2468
2469
  processBinaryOpExpression,
@@ -6330,11 +6331,11 @@ ${input.slice(result.pos)}
6330
6331
  }
6331
6332
  var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
6332
6333
  var open = $1;
6333
- var exp = $2;
6334
+ var expression = $2;
6334
6335
  var ws = $3;
6335
6336
  var close = $4;
6336
- if (exp.type === "SliceParameters") {
6337
- const { start, end, children } = exp;
6337
+ if (expression.type === "SliceParameters") {
6338
+ const { start, end, children } = expression;
6338
6339
  return {
6339
6340
  type: "SliceExpression",
6340
6341
  start,
@@ -6348,7 +6349,8 @@ ${input.slice(result.pos)}
6348
6349
  }
6349
6350
  return {
6350
6351
  type: "Index",
6351
- children: $0
6352
+ children: $0,
6353
+ expression
6352
6354
  };
6353
6355
  });
6354
6356
  var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
@@ -9739,12 +9741,40 @@ ${input.slice(result.pos)}
9739
9741
  const last = lastAccessInCallExpression(value);
9740
9742
  if (!last)
9741
9743
  return $skip;
9742
- let name;
9743
- if (last.type === "Index") {
9744
- name = {
9745
- type: "ComputedPropertyName",
9746
- children: last.children
9747
- };
9744
+ let name, hoistDec, ref, refAssignment;
9745
+ const { expression, type } = last;
9746
+ if (type === "Index") {
9747
+ ref = maybeRef(expression);
9748
+ if (ref !== expression) {
9749
+ hoistDec = {
9750
+ type: "Declaration",
9751
+ children: ["let ", ref]
9752
+ };
9753
+ refAssignment = {
9754
+ type: "Assignment",
9755
+ children: [ref, " = ", expression]
9756
+ };
9757
+ name = {
9758
+ type: "ComputedPropertyName",
9759
+ children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
9760
+ };
9761
+ value = {
9762
+ ...value,
9763
+ children: value.children.map((c) => {
9764
+ if (c === last)
9765
+ return {
9766
+ type: "Index",
9767
+ children: ["[", ref, "]"]
9768
+ };
9769
+ return c;
9770
+ })
9771
+ };
9772
+ } else {
9773
+ name = {
9774
+ type: "ComputedPropertyName",
9775
+ children: last.children
9776
+ };
9777
+ }
9748
9778
  } else {
9749
9779
  ({ name } = last);
9750
9780
  if (!name)
@@ -9755,7 +9785,8 @@ ${input.slice(result.pos)}
9755
9785
  children: [ws, name, ": ", value],
9756
9786
  name,
9757
9787
  value,
9758
- names: []
9788
+ names: [],
9789
+ hoistDec
9759
9790
  };
9760
9791
  });
9761
9792
  function PropertyDefinition(state) {
@@ -23375,6 +23406,7 @@ ${input.slice(result.pos)}
23375
23406
  lastAccessInCallExpression,
23376
23407
  literalValue,
23377
23408
  makeLeftHandSideExpression,
23409
+ maybeRef,
23378
23410
  modifyString,
23379
23411
  processBinaryOpExpression,
23380
23412
  processCallMemberExpression,
package/dist/main.js CHANGED
@@ -2462,6 +2462,7 @@ var require_lib = __commonJS({
2462
2462
  literalValue,
2463
2463
  makeAsConst,
2464
2464
  makeLeftHandSideExpression,
2465
+ maybeRef,
2465
2466
  modifyString,
2466
2467
  needsRef,
2467
2468
  processBinaryOpExpression,
@@ -6329,11 +6330,11 @@ ${input.slice(result.pos)}
6329
6330
  }
6330
6331
  var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
6331
6332
  var open = $1;
6332
- var exp = $2;
6333
+ var expression = $2;
6333
6334
  var ws = $3;
6334
6335
  var close = $4;
6335
- if (exp.type === "SliceParameters") {
6336
- const { start, end, children } = exp;
6336
+ if (expression.type === "SliceParameters") {
6337
+ const { start, end, children } = expression;
6337
6338
  return {
6338
6339
  type: "SliceExpression",
6339
6340
  start,
@@ -6347,7 +6348,8 @@ ${input.slice(result.pos)}
6347
6348
  }
6348
6349
  return {
6349
6350
  type: "Index",
6350
- children: $0
6351
+ children: $0,
6352
+ expression
6351
6353
  };
6352
6354
  });
6353
6355
  var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
@@ -9738,12 +9740,40 @@ ${input.slice(result.pos)}
9738
9740
  const last = lastAccessInCallExpression(value);
9739
9741
  if (!last)
9740
9742
  return $skip;
9741
- let name;
9742
- if (last.type === "Index") {
9743
- name = {
9744
- type: "ComputedPropertyName",
9745
- children: last.children
9746
- };
9743
+ let name, hoistDec, ref, refAssignment;
9744
+ const { expression, type } = last;
9745
+ if (type === "Index") {
9746
+ ref = maybeRef(expression);
9747
+ if (ref !== expression) {
9748
+ hoistDec = {
9749
+ type: "Declaration",
9750
+ children: ["let ", ref]
9751
+ };
9752
+ refAssignment = {
9753
+ type: "Assignment",
9754
+ children: [ref, " = ", expression]
9755
+ };
9756
+ name = {
9757
+ type: "ComputedPropertyName",
9758
+ children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
9759
+ };
9760
+ value = {
9761
+ ...value,
9762
+ children: value.children.map((c) => {
9763
+ if (c === last)
9764
+ return {
9765
+ type: "Index",
9766
+ children: ["[", ref, "]"]
9767
+ };
9768
+ return c;
9769
+ })
9770
+ };
9771
+ } else {
9772
+ name = {
9773
+ type: "ComputedPropertyName",
9774
+ children: last.children
9775
+ };
9776
+ }
9747
9777
  } else {
9748
9778
  ({ name } = last);
9749
9779
  if (!name)
@@ -9754,7 +9784,8 @@ ${input.slice(result.pos)}
9754
9784
  children: [ws, name, ": ", value],
9755
9785
  name,
9756
9786
  value,
9757
- names: []
9787
+ names: [],
9788
+ hoistDec
9758
9789
  };
9759
9790
  });
9760
9791
  function PropertyDefinition(state) {
@@ -23374,6 +23405,7 @@ ${input.slice(result.pos)}
23374
23405
  lastAccessInCallExpression,
23375
23406
  literalValue,
23376
23407
  makeLeftHandSideExpression,
23408
+ maybeRef,
23377
23409
  modifyString,
23378
23410
  processBinaryOpExpression,
23379
23411
  processCallMemberExpression,
package/dist/main.mjs CHANGED
@@ -2460,6 +2460,7 @@ var require_lib = __commonJS({
2460
2460
  literalValue,
2461
2461
  makeAsConst,
2462
2462
  makeLeftHandSideExpression,
2463
+ maybeRef,
2463
2464
  modifyString,
2464
2465
  needsRef,
2465
2466
  processBinaryOpExpression,
@@ -6327,11 +6328,11 @@ ${input.slice(result.pos)}
6327
6328
  }
6328
6329
  var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
6329
6330
  var open = $1;
6330
- var exp = $2;
6331
+ var expression = $2;
6331
6332
  var ws = $3;
6332
6333
  var close = $4;
6333
- if (exp.type === "SliceParameters") {
6334
- const { start, end, children } = exp;
6334
+ if (expression.type === "SliceParameters") {
6335
+ const { start, end, children } = expression;
6335
6336
  return {
6336
6337
  type: "SliceExpression",
6337
6338
  start,
@@ -6345,7 +6346,8 @@ ${input.slice(result.pos)}
6345
6346
  }
6346
6347
  return {
6347
6348
  type: "Index",
6348
- children: $0
6349
+ children: $0,
6350
+ expression
6349
6351
  };
6350
6352
  });
6351
6353
  var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
@@ -9736,12 +9738,40 @@ ${input.slice(result.pos)}
9736
9738
  const last = lastAccessInCallExpression(value);
9737
9739
  if (!last)
9738
9740
  return $skip;
9739
- let name;
9740
- if (last.type === "Index") {
9741
- name = {
9742
- type: "ComputedPropertyName",
9743
- children: last.children
9744
- };
9741
+ let name, hoistDec, ref, refAssignment;
9742
+ const { expression, type } = last;
9743
+ if (type === "Index") {
9744
+ ref = maybeRef(expression);
9745
+ if (ref !== expression) {
9746
+ hoistDec = {
9747
+ type: "Declaration",
9748
+ children: ["let ", ref]
9749
+ };
9750
+ refAssignment = {
9751
+ type: "Assignment",
9752
+ children: [ref, " = ", expression]
9753
+ };
9754
+ name = {
9755
+ type: "ComputedPropertyName",
9756
+ children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
9757
+ };
9758
+ value = {
9759
+ ...value,
9760
+ children: value.children.map((c) => {
9761
+ if (c === last)
9762
+ return {
9763
+ type: "Index",
9764
+ children: ["[", ref, "]"]
9765
+ };
9766
+ return c;
9767
+ })
9768
+ };
9769
+ } else {
9770
+ name = {
9771
+ type: "ComputedPropertyName",
9772
+ children: last.children
9773
+ };
9774
+ }
9745
9775
  } else {
9746
9776
  ({ name } = last);
9747
9777
  if (!name)
@@ -9752,7 +9782,8 @@ ${input.slice(result.pos)}
9752
9782
  children: [ws, name, ": ", value],
9753
9783
  name,
9754
9784
  value,
9755
- names: []
9785
+ names: [],
9786
+ hoistDec
9756
9787
  };
9757
9788
  });
9758
9789
  function PropertyDefinition(state) {
@@ -23372,6 +23403,7 @@ ${input.slice(result.pos)}
23372
23403
  lastAccessInCallExpression,
23373
23404
  literalValue,
23374
23405
  makeLeftHandSideExpression,
23406
+ maybeRef,
23375
23407
  modifyString,
23376
23408
  processBinaryOpExpression,
23377
23409
  processCallMemberExpression,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",