Skip to content

Commit

Permalink
handle characters in js property accessing; bump 0.4.14
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Aug 6, 2021
1 parent 135d9e6 commit 7e126ca
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
&& cargo run --bin cr calcit/snapshots/test.cirru --emit-js --once
&& ln -s ../../ node_modules/@calcit/procs
&& cp -v scripts/main.js js-out/
&& target=node yarn webpack && node js-out/bundle.js
&& yarn webpack && node js-out/bundle.js
- uses: katyo/publish-crates@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
&& cargo run --bin cr calcit/snapshots/test.cirru --emit-js --once
&& ln -s ../../ node_modules/@calcit/procs
&& cp -v scripts/main.js js-out/
&& target=node yarn webpack && node js-out/bundle.js
&& yarn webpack && node js-out/bundle.js
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.4.13"
version = "0.4.14"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down
5 changes: 4 additions & 1 deletion calcit/snapshots/test-js.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
= |number (js/typeof 1)
js/console.log "|is a Number"

.log js/console |demo
.!log js/console |demo
js/console.log "|Dates in difference syntax" (.!now js/Date) (.now js/Date)
js/console.log $ .-PI js/Math

Expand All @@ -42,6 +42,9 @@
set! (.-a a) 2
assert= (.-a a) 2

set! (.-a-b a) 3
assert= (.-a-b a) 3

assert= 2 $ aget (to-js-data $ [] 1 2 3) 1

assert-detect identity $ instance? js/Number (new js/Number 1)
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "@calcit/procs",
"version": "0.4.13",
"version": "0.4.14",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^15.12.2",
"@types/node": "^16.4.13",
"estrella": "^1.4.1",
"typescript": "^4.3.2",
"webpack": "^5.39.0",
"webpack": "^5.49.0",
"webpack-cli": "^4.7.2"
},
"scripts": {
"compile": "rm -rfv lib/* && tsc",
"procs-link": "ln -s ../../ node_modules/@calcit/procs",
"cp-mac": "cargo build --release && rm -rfv builds/* && node scripts/cp-version.js && scp builds/* rsync-user@calcit-lang.org:/web-assets/repo/calcit-lang/binaries/macos/",
"try-rs": "cargo run --bin cr -- calcit/snapshots/test.cirru -1",
"try-js": "cargo run --bin cr -- calcit/snapshots/test.cirru --emit-js -1 && target=node yarn webpack && node js-out/bundle.js"
"try-js": "cargo run --bin cr -- calcit/snapshots/test.cirru --emit-js -1 && yarn webpack && node js-out/bundle.js"
},
"dependencies": {
"@calcit/ternary-tree": "0.0.16",
Expand Down
13 changes: 12 additions & 1 deletion src/codegen/emit_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ fn gen_call_code(
)),
None => Err(format!("property accessor takes only 1 argument, {:?}", xs)),
}
} else {
} else if matches_js_var(name) {
match body.get(0) {
Some(obj) => Ok(format!(
"{}{}.{}",
Expand All @@ -479,6 +479,17 @@ fn gen_call_code(
)),
None => Err(format!("property accessor takes only 1 argument, {:?}", xs)),
}
} else {
// includes characters that need to be escaped
match body.get(0) {
Some(obj) => Ok(format!(
"{}{}[\"{}\"]",
return_code,
to_js_code(&obj, ns, local_defs, file_imports, &None)?,
name,
)),
None => Err(format!("property accessor takes only 1 argument, {:?}", xs)),
}
}
}
_ if s.starts_with(".!") => {
Expand Down
2 changes: 1 addition & 1 deletion ts-src/calcit.procs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CALCIT VERSION
export const calcit_version = "0.4.13";
export const calcit_version = "0.4.14";

import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
import { parse } from "@cirru/parser.ts";
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let path = require("path");

let bundleTarget = process.env.target === "node" ? "node" : "web";
let bundleTarget = process.env.target === "web" ? "web" : "node";

console.log("bundle mode:", bundleTarget);

Expand Down
138 changes: 79 additions & 59 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e126ca

Please sign in to comment.