@oddo/lang 0.0.3 → 0.0.5

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/lexer.mjs
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/lexer.mjs
2
2
  var _chevrotain = require('chevrotain');
3
3
  var Identifier = _chevrotain.createToken.call(void 0, {
4
4
  name: "Identifier",
@@ -3449,6 +3449,7 @@ function decodeHTMLEntities(text) {
3449
3449
  });
3450
3450
  }
3451
3451
  function convertJSXChildren(childrenCST) {
3452
+ var _a;
3452
3453
  if (!childrenCST || childrenCST.length === 0) return [];
3453
3454
  const childrenWithOffsets = childrenCST.map((child) => {
3454
3455
  const firstOffset = getFirstTokenOffset(child);
@@ -3459,18 +3460,9 @@ function convertJSXChildren(childrenCST) {
3459
3460
  const result = [];
3460
3461
  for (let i = 0; i < childrenWithOffsets.length; i++) {
3461
3462
  const current = childrenWithOffsets[i];
3462
- if (i > 0 && sourceText) {
3463
- const prev = childrenWithOffsets[i - 1];
3464
- const gapStart = prev.lastOffset + 1;
3465
- const gapEnd = current.firstOffset;
3466
- if (gapEnd > gapStart) {
3467
- const gap = sourceText.slice(gapStart, gapEnd);
3468
- if (gap && /\s/.test(gap)) {
3469
- result.push({ type: "jsxText", value: " " });
3470
- }
3471
- }
3472
- }
3473
- const converted = convertJSXChild(current.cst);
3463
+ const prevEnd = i > 0 ? childrenWithOffsets[i - 1].lastOffset + 1 : void 0;
3464
+ const nextStart = (_a = childrenWithOffsets[i + 1]) == null ? void 0 : _a.firstOffset;
3465
+ const converted = convertJSXChild(current.cst, prevEnd, nextStart);
3474
3466
  if (converted !== null) {
3475
3467
  result.push(converted);
3476
3468
  }
@@ -3503,7 +3495,7 @@ function getLastTokenOffset(node) {
3503
3495
  }
3504
3496
  return lastOffset;
3505
3497
  }
3506
- function convertJSXChild(cst) {
3498
+ function convertJSXChild(cst, startBoundary, endBoundary) {
3507
3499
  if (cst.children.jsxElement) {
3508
3500
  return convertJSXElement(getFirstChild(cst, "jsxElement"));
3509
3501
  }
@@ -3536,6 +3528,22 @@ function convertJSXChild(cst) {
3536
3528
  }
3537
3529
  if (allTokens2.length > 0) {
3538
3530
  allTokens2.sort((a, b) => a.offset - b.offset);
3531
+ const firstToken = allTokens2[0];
3532
+ const lastToken = allTokens2[allTokens2.length - 1];
3533
+ const lastTokenEnd = lastToken.token.endOffset !== void 0 ? lastToken.token.endOffset : lastToken.token.startOffset + lastToken.token.image.length - 1;
3534
+ if (sourceText && (startBoundary !== void 0 || endBoundary !== void 0)) {
3535
+ const textStart = _nullishCoalesce(startBoundary, () => ( firstToken.offset));
3536
+ const textEnd = _nullishCoalesce(endBoundary, () => ( lastTokenEnd + 1));
3537
+ const textValue2 = sourceText.slice(textStart, textEnd);
3538
+ if (textValue2) {
3539
+ const decodedValue2 = decodeHTMLEntities(textValue2);
3540
+ return {
3541
+ type: "jsxText",
3542
+ value: decodedValue2
3543
+ };
3544
+ }
3545
+ return null;
3546
+ }
3539
3547
  let textValue = "";
3540
3548
  for (let i = 0; i < allTokens2.length; i++) {
3541
3549
  const current = allTokens2[i];
@@ -3660,11 +3668,21 @@ function wrapDependenciesWithCalls(arrowFunc, deps) {
3660
3668
  traverse(tempFile, {
3661
3669
  noScope: true,
3662
3670
  Identifier(path) {
3671
+ var _a;
3663
3672
  if (t.isArrowFunctionExpression(path.parent) && path.parent.params.includes(path.node)) {
3664
3673
  return;
3665
3674
  }
3666
3675
  const parent = path.parent;
3667
- const isMemberProp = t.isMemberExpression(parent) && parent.property === path.node && !parent.computed;
3676
+ if (t.isObjectPattern(parent) || t.isArrayPattern(parent)) {
3677
+ return;
3678
+ }
3679
+ if (t.isVariableDeclarator(parent) && parent.id === path.node) {
3680
+ return;
3681
+ }
3682
+ if (t.isObjectProperty(parent) && t.isObjectPattern((_a = path.parentPath) == null ? void 0 : _a.parent)) {
3683
+ return;
3684
+ }
3685
+ const isMemberProp = (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.property === path.node && !parent.computed;
3668
3686
  const isObjectKey = t.isObjectProperty(parent) && parent.key === path.node && !parent.shorthand;
3669
3687
  const isShorthand = t.isObjectProperty(parent) && parent.shorthand && parent.key === path.node;
3670
3688
  if (depSet.has(path.node.name) && !isMemberProp && !isObjectKey && !locals.has(path.node.name)) {
@@ -3717,7 +3735,8 @@ function createLiftedExpr(valueExpr, identifiers) {
3717
3735
  );
3718
3736
  }
3719
3737
  function createReactiveExpr(valueExpr, attrExpression = false) {
3720
- const identifiers = extractIdentifiers(valueExpr);
3738
+ const allIdentifiers = extractIdentifiers(valueExpr);
3739
+ const identifiers = getReactiveDeps(allIdentifiers);
3721
3740
  const pragma = attrExpression ? "computed" : "x";
3722
3741
  if (identifiers.length === 0) {
3723
3742
  if (t.isLiteral(valueExpr)) {
@@ -3771,7 +3790,8 @@ var MODIFIER_TRANSFORMATIONS = {
3771
3790
  needsImport: true,
3772
3791
  // @computed sum = x + y -> const sum = _computed((x, y) => x() + y(), [x, y])
3773
3792
  transform: (valueExpr, leftExpr) => {
3774
- const identifiers = extractIdentifiers(valueExpr);
3793
+ const allIds = extractIdentifiers(valueExpr);
3794
+ const identifiers = getReactiveDeps(allIds);
3775
3795
  const params = identifiers.map((id) => t.identifier(id));
3776
3796
  const deps = identifiers.map((id) => t.identifier(id));
3777
3797
  const arrowFunc = t.arrowFunctionExpression(params, valueExpr);
@@ -3792,7 +3812,8 @@ var MODIFIER_TRANSFORMATIONS = {
3792
3812
  needsImport: true,
3793
3813
  // @react sum = x + y -> const sum = _react((x, y) => x() + y(), [x, y])
3794
3814
  transform: (valueExpr, leftExpr) => {
3795
- const identifiers = extractIdentifiers(valueExpr);
3815
+ const allIds = extractIdentifiers(valueExpr);
3816
+ const identifiers = getReactiveDeps(allIds);
3796
3817
  const params = identifiers.map((id) => t.identifier(id));
3797
3818
  const deps = identifiers.map((id) => t.identifier(id));
3798
3819
  const arrowFunc = t.arrowFunctionExpression(params, valueExpr);
@@ -3884,7 +3905,7 @@ var MODIFIER_TRANSFORMATIONS = {
3884
3905
  noScope: true,
3885
3906
  Identifier(path) {
3886
3907
  const parent = path.parent;
3887
- const isMemberProp = t.isMemberExpression(parent) && parent.property === path.node && !parent.computed;
3908
+ const isMemberProp = (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.property === path.node && !parent.computed;
3888
3909
  const isObjectKey = t.isObjectProperty(parent) && parent.key === path.node && !parent.shorthand;
3889
3910
  const isShorthand = t.isObjectProperty(parent) && parent.shorthand && parent.key === path.node;
3890
3911
  if (callableIds.has(path.node.name) && !isMemberProp && !isObjectKey) {
@@ -4028,7 +4049,7 @@ var mutableVariables = /* @__PURE__ */ new Set();
4028
4049
  var moduleScope = null;
4029
4050
  var currentScope = null;
4030
4051
  function declareVariable(name, type) {
4031
- const reactive = type === "state" || type === "computed" || type === "param";
4052
+ const reactive = type === "state" || type === "computed" || type === "param" || type === "import-oddo";
4032
4053
  currentScope[name] = { type, reactive };
4033
4054
  }
4034
4055
  function isDeclared(name) {
@@ -4106,6 +4127,20 @@ function collectOddoIdentifiers(node, names = /* @__PURE__ */ new Set()) {
4106
4127
  }
4107
4128
  }
4108
4129
  }
4130
+ if (node.type === "importStatement") {
4131
+ const source = node.source || "";
4132
+ const isOddoImport = source.endsWith(".oddo");
4133
+ const type = isOddoImport ? "import-oddo" : "import-js";
4134
+ if (node.defaultImport) {
4135
+ declareVariable(node.defaultImport, type);
4136
+ }
4137
+ for (const spec of node.specifiers || []) {
4138
+ const localName = spec.local || spec.imported;
4139
+ if (localName) {
4140
+ declareVariable(localName, type);
4141
+ }
4142
+ }
4143
+ }
4109
4144
  if (node.type === "arrowFunction") {
4110
4145
  const parentScope = currentScope;
4111
4146
  currentScope = Object.create(parentScope);