olum-compiler 0.9.3 → 0.9.7

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/events.js CHANGED
@@ -31,7 +31,12 @@ function handleEvents(body, counter, filePath, anonHandlers) {
31
31
  let methods = attrValue.split("),");
32
32
  methods = methods.map(str => (str.replace(/\)$/, "") + ")").trim());
33
33
  let methodsNames = methods.map(str => (str.trim().split("(")[0]).trim());
34
- let methodsArgs = methods.map(str => (str.trim().split("(")[1].replace(/\)$/, "")).trim());
34
+ // args = everything between the FIRST "(" and the LAST ")", so arguments that themselves
35
+ // contain parens (e.g. toggle(props().todo.id)) aren't truncated at the inner "(".
36
+ let methodsArgs = methods.map(str => {
37
+ const s = str.trim();
38
+ return s.slice(s.indexOf("(") + 1, s.lastIndexOf(")")).trim();
39
+ });
35
40
 
36
41
  function handle$event(str) {
37
42
  return str.replace(/\$event/g, "'$event'")
package/lib/htmlParser.js CHANGED
@@ -48,7 +48,14 @@ function htmlparser(str, counter, filePath) {
48
48
  // appears as a literal `{` here. Wrapping each remaining `{expr}` in `olum.esc(...)` therefore
49
49
  // escapes user-facing output (preventing XSS and "special characters break the page" bugs) while
50
50
  // leaving structural code untouched. `[^{}]+` keeps each match to a single, non-nested pair.
51
- content = content.replace(/\{([^{}]+)\}/g, (match, expr) => expr.trim() === "children" ? "${children}" : "${olum.esc(" + expr + ")}");
51
+ // slot content (`children` and `props().children`) is trusted markup authored in the parent
52
+ // template, not user input, so it is emitted RAW (no esc) — escaping it would show its tags as text.
53
+ content = content.replace(/\{([^{}]+)\}/g, (match, expr) => {
54
+ const raw = expr.trim();
55
+ if (raw === "children") return "${children}";
56
+ if (/^props\(\s*\)\.children$/.test(raw)) return "${" + raw + "}";
57
+ return "${olum.esc(" + expr + ")}";
58
+ });
52
59
 
53
60
  content = content.replace(/&/g, "&"); // fix entity
54
61
  content = content.replace(/=>/g, "=>"); // preserve arrow functions
package/lib/parser.js CHANGED
@@ -5,7 +5,7 @@ const jsParser = require("./jsParser");
5
5
  const getImports = require("./getImports");
6
6
  const toJs = require("./toJs");
7
7
  const path = require("path");
8
- const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, minifyJS, libsMap } = require("./helpers");
8
+ const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, libsMap } = require("./helpers");
9
9
  const createSourceMap = require("./sourcemap");
10
10
 
11
11
  const parser = (str, counter, filePath) => {
@@ -105,37 +105,14 @@ const parser = (str, counter, filePath) => {
105
105
  return entries.join(",");
106
106
  }
107
107
 
108
- // resolves this instance's store slot via _storeKey (the runtime instance key)
109
- const propsProxy = `const props = new Proxy({}, {
110
- get(_, key) {
111
- const entry = olum.app.store[_storeKey];
112
- return entry && entry.incomingProps ? entry.incomingProps[key] : undefined;
113
- },
114
- set(_, key, val) {
115
- const entry = olum.app.store[_storeKey];
116
- if (entry && entry.parentCompName && entry.incomingPropSources) {
117
- const desc = entry.incomingPropSources[key];
118
- if (desc) {
119
- const parent = olum.app.store[entry.parentCompName];
120
- if (parent) {
121
- // state source -> write parent state (triggers re-render); props source -> chain up the parent's props proxy
122
- if (desc.kind === "state" && parent.stateProps) parent.stateProps[desc.key] = val;
123
- else if (desc.kind === "props" && parent.incomingPropsProxy) parent.incomingPropsProxy[desc.key] = val;
124
- }
125
- }
126
- }
127
- return true;
128
- }
129
- });`;
130
-
131
- // children is declared inside getElm (not at factory-call time) so it re-reads the store on every render
132
- const childrenVar = `const children=(olum.app.store[_storeKey]&&olum.app.store[_storeKey].children)||"";`;
133
- const routerParamsProxy = `const params = new Proxy({},{ get(_, key) { const values = extractParams(currentFilePath, location.pathname); return values[key];}, ownKeys() { return Reflect.ownKeys(extractParams(currentFilePath, location.pathname));},getOwnPropertyDescriptor() {return {enumerable: true,configurable: true,};},});`;
108
+ js = js.replace(/params\(/, `params("${filePath}",location.pathname`); // handle params of router
109
+ // bind the imported props() accessor to this instance's runtime store key: props() -> props(_storeKey)
110
+ js = js.replace(/props\(\s*\)/g, "props(_storeKey)");
111
+ html = html.replace(/props\(\s*\)/g, "props(_storeKey)");
134
112
 
135
- // bind props proxy at the top to be accessed by ${js} code
136
- return `${breaks}${imports ? imports.join("\n") + "\n" : ""}export default (_instanceKey) => {const currentFilePath = "${filePath}"; ${routerParamsProxy} const _storeKey=_instanceKey||"${compName}"; ${minifyJS(propsProxy)}${js}
113
+ return `${breaks}${imports ? imports.join("\n") + "\n" : ""}export default (_instanceKey) => {const _storeKey=_instanceKey||"${compName}"; ${js}
137
114
  var el_${currentID} = olum.mkElm("div", "${compName}", "${currentID}");
138
- var $0 = el_${currentID};
115
+ var host = el_${currentID};
139
116
  var methods_${currentID} = {${globalMethods}};
140
117
  var olum_${currentID} = {
141
118
  ${css}
@@ -144,7 +121,6 @@ const parser = (str, counter, filePath) => {
144
121
  compName: "${compName}",
145
122
  components: {${mkComponentsList(comps)}},
146
123
  get getElm() {
147
- ${childrenVar}
148
124
  el_${currentID}.innerHTML = \`
149
125
  ${html}\`;
150
126
  olum.injectStyle("${compName}", olum_${currentID}.__style__());
@@ -163,7 +139,7 @@ const parser = (str, counter, filePath) => {
163
139
  props: olum_${currentID}.props,
164
140
  __OLUM__: olum_${currentID},
165
141
  el: el_${currentID},
166
- incomingPropsProxy: props,
142
+ incomingPropsProxy: olum.props(_storeKey),
167
143
  ${isDev ? `stateProps: ${hasState ? "state" : "null"},` : ""}
168
144
  hooks: {
169
145
  mounted: typeof mounted !== "undefined" ? mounted : null,
@@ -55,7 +55,8 @@ function parseProps(attrsStr) {
55
55
  // parent's own prop (the setter recurses until it reaches whoever holds it in state).
56
56
  // format: propName:kind:srcKey (kind = state | props)
57
57
  const stateMatch = expr.trim().match(/^state\.(\w+)$/);
58
- const propsMatch = expr.trim().match(/^props\.(\w+)$/);
58
+ // props source is the wrapper call `props().X` (old proxy access `props.X` also accepted)
59
+ const propsMatch = expr.trim().match(/^props(?:\(\s*\))?\.(\w+)$/);
59
60
  if (stateMatch) srcEntries.push(propName + ':state:' + stateMatch[1]);
60
61
  else if (propsMatch) srcEntries.push(propName + ':props:' + propsMatch[1]);
61
62
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "0.9.3",
3
+ "version": "0.9.7",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {