Skip to content

Commit

Permalink
fix: use global Go to store text due to go.argv limitation (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Apr 6, 2022
1 parent 37a08f6 commit 174f66c
Show file tree
Hide file tree
Showing 11 changed files with 9,078 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-moose-shake.md
@@ -0,0 +1,5 @@
---
"sh-syntax": patch
---

fix: use global Go to store text due to go.argv limitation
2 changes: 1 addition & 1 deletion .eslintignore
@@ -1,5 +1,5 @@
coverage
lib
vendors
vendors/*.js
CHANGELOG.md
!/.*.js
27 changes: 24 additions & 3 deletions main.go
Expand Up @@ -214,20 +214,41 @@ func main() {
Go.Set("__shProcessing", js.ValueOf(map[string]interface{}{}))
}

__shProcessing := Go.Get("__shProcessing")

if __shProcessing.Get(*uid).IsUndefined() {
__shProcessing.Set(*uid, js.ValueOf(map[string]interface{}{}))
}

Text := __shProcessing.Get(*uid).Get("Text")

var finalText string

if Text.IsUndefined() {
if *ast == "" {
finalText = *text
} else {
finalText = *originalText
}
} else {
finalText = Text.String()
}

var Data interface{}
var Error interface{}

if *ast == "" {
file, err := parse(*text, *filepath)
file, err := parse(finalText, *filepath)
Data = fileToMap(*file)
Error = mapParseError(err)
} else {
result, err := print(*originalText, *filepath)
result, err := print(finalText, *filepath)
Data = result
Error = mapParseError(err)
}

Go.Get("__shProcessing").Set(*uid, js.ValueOf(map[string]interface{}{
__shProcessing.Set(*uid, js.ValueOf(map[string]interface{}{
"Text": nil,
"Data": Data,
"Error": Error,
}))
Expand Down
Binary file modified main.wasm
Binary file not shown.
15 changes: 10 additions & 5 deletions package.json
Expand Up @@ -12,10 +12,15 @@
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"exports": {
"import": "./lib/index.js",
"require": "./lib/index.cjs",
"browser": "./lib/browser.js",
"types": "./lib/index.d.ts"
".": {
"import": "./lib/index.js",
"require": "./lib/index.cjs",
"browser": "./lib/browser.js",
"types": "./lib/index.d.ts"
},
"./package.json": "./package.json",
"./vendors/wasm_exec": "./vendors/wasm_exec.js",
"./vendors/wasm_exec.js": "./vendors/wasm_exec.js"
},
"types": "./lib/index.d.ts",
"files": [
Expand Down Expand Up @@ -43,7 +48,7 @@
"tslib": "^2.3.1"
},
"devDependencies": {
"@1stg/lib-config": "^5.4.0",
"@1stg/lib-config": "^5.5.0",
"@changesets/changelog-github": "^0.4.4",
"@changesets/cli": "^2.22.0",
"@types/jest": "^27.4.1",
Expand Down
102 changes: 48 additions & 54 deletions pnpm-lock.yaml

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

0 comments on commit 174f66c

Please sign in to comment.