喵了个咪
5 years ago
2541 changed files with 410435 additions and 696 deletions
-
6.idea/go-service-template.iml
-
3238.idea/workspace.xml
-
327govue2/bindata.go
-
34govue2/cache.go
-
111govue2/cmd/main.go
-
57govue2/config.go
-
8govue2/govue-js-src/build.js
-
16govue2/govue-js-src/govue.js
-
15govue2/govue-js-src/node_modules/.bin/JSONStream
-
17govue2/govue-js-src/node_modules/.bin/JSONStream.cmd
-
18govue2/govue-js-src/node_modules/.bin/JSONStream.ps1
-
15govue2/govue-js-src/node_modules/.bin/acorn
-
17govue2/govue-js-src/node_modules/.bin/acorn.cmd
-
18govue2/govue-js-src/node_modules/.bin/acorn.ps1
-
15govue2/govue-js-src/node_modules/.bin/browser-pack
-
17govue2/govue-js-src/node_modules/.bin/browser-pack.cmd
-
18govue2/govue-js-src/node_modules/.bin/browser-pack.ps1
-
15govue2/govue-js-src/node_modules/.bin/browserify
-
17govue2/govue-js-src/node_modules/.bin/browserify.cmd
-
18govue2/govue-js-src/node_modules/.bin/browserify.ps1
-
15govue2/govue-js-src/node_modules/.bin/deps-sort
-
17govue2/govue-js-src/node_modules/.bin/deps-sort.cmd
-
18govue2/govue-js-src/node_modules/.bin/deps-sort.ps1
-
15govue2/govue-js-src/node_modules/.bin/detective
-
17govue2/govue-js-src/node_modules/.bin/detective.cmd
-
18govue2/govue-js-src/node_modules/.bin/detective.ps1
-
15govue2/govue-js-src/node_modules/.bin/envify
-
17govue2/govue-js-src/node_modules/.bin/envify.cmd
-
18govue2/govue-js-src/node_modules/.bin/envify.ps1
-
15govue2/govue-js-src/node_modules/.bin/esparse
-
17govue2/govue-js-src/node_modules/.bin/esparse.cmd
-
18govue2/govue-js-src/node_modules/.bin/esparse.ps1
-
15govue2/govue-js-src/node_modules/.bin/esvalidate
-
17govue2/govue-js-src/node_modules/.bin/esvalidate.cmd
-
18govue2/govue-js-src/node_modules/.bin/esvalidate.ps1
-
15govue2/govue-js-src/node_modules/.bin/he
-
17govue2/govue-js-src/node_modules/.bin/he.cmd
-
18govue2/govue-js-src/node_modules/.bin/he.ps1
-
15govue2/govue-js-src/node_modules/.bin/insert-module-globals
-
17govue2/govue-js-src/node_modules/.bin/insert-module-globals.cmd
-
18govue2/govue-js-src/node_modules/.bin/insert-module-globals.ps1
-
15govue2/govue-js-src/node_modules/.bin/miller-rabin
-
17govue2/govue-js-src/node_modules/.bin/miller-rabin.cmd
-
18govue2/govue-js-src/node_modules/.bin/miller-rabin.ps1
-
15govue2/govue-js-src/node_modules/.bin/module-deps
-
17govue2/govue-js-src/node_modules/.bin/module-deps.cmd
-
18govue2/govue-js-src/node_modules/.bin/module-deps.ps1
-
15govue2/govue-js-src/node_modules/.bin/sha.js
-
17govue2/govue-js-src/node_modules/.bin/sha.js.cmd
-
18govue2/govue-js-src/node_modules/.bin/sha.js.ps1
-
15govue2/govue-js-src/node_modules/.bin/umd
-
17govue2/govue-js-src/node_modules/.bin/umd.cmd
-
18govue2/govue-js-src/node_modules/.bin/umd.ps1
-
15govue2/govue-js-src/node_modules/.bin/undeclared-identifiers
-
17govue2/govue-js-src/node_modules/.bin/undeclared-identifiers.cmd
-
18govue2/govue-js-src/node_modules/.bin/undeclared-identifiers.ps1
-
8govue2/govue-js-src/node_modules/JSONStream/.travis.yml
-
15govue2/govue-js-src/node_modules/JSONStream/LICENSE.APACHE2
-
24govue2/govue-js-src/node_modules/JSONStream/LICENSE.MIT
-
12govue2/govue-js-src/node_modules/JSONStream/bin.js
-
13govue2/govue-js-src/node_modules/JSONStream/examples/all_docs.js
-
247govue2/govue-js-src/node_modules/JSONStream/index.js
-
207govue2/govue-js-src/node_modules/JSONStream/readme.markdown
-
41govue2/govue-js-src/node_modules/JSONStream/test/bool.js
-
18govue2/govue-js-src/node_modules/JSONStream/test/browser.js
-
27govue2/govue-js-src/node_modules/JSONStream/test/destroy_missing.js
-
29govue2/govue-js-src/node_modules/JSONStream/test/doubledot1.js
-
30govue2/govue-js-src/node_modules/JSONStream/test/doubledot2.js
-
44govue2/govue-js-src/node_modules/JSONStream/test/empty.js
-
45govue2/govue-js-src/node_modules/JSONStream/test/error_contents.js
-
39govue2/govue-js-src/node_modules/JSONStream/test/fn.js
-
135govue2/govue-js-src/node_modules/JSONStream/test/gen.js
-
55govue2/govue-js-src/node_modules/JSONStream/test/header_footer.js
-
34govue2/govue-js-src/node_modules/JSONStream/test/issues.js
-
105govue2/govue-js-src/node_modules/JSONStream/test/keys.js
-
40govue2/govue-js-src/node_modules/JSONStream/test/map.js
-
36govue2/govue-js-src/node_modules/JSONStream/test/multiple_objects.js
-
29govue2/govue-js-src/node_modules/JSONStream/test/multiple_objects_error.js
-
28govue2/govue-js-src/node_modules/JSONStream/test/null.js
-
29govue2/govue-js-src/node_modules/JSONStream/test/parsejson.js
-
13govue2/govue-js-src/node_modules/JSONStream/test/run.js
-
41govue2/govue-js-src/node_modules/JSONStream/test/stringify.js
-
47govue2/govue-js-src/node_modules/JSONStream/test/stringify_object.js
-
35govue2/govue-js-src/node_modules/JSONStream/test/test.js
-
29govue2/govue-js-src/node_modules/JSONStream/test/test2.js
-
41govue2/govue-js-src/node_modules/JSONStream/test/two-ways.js
-
22govue2/govue-js-src/node_modules/acorn-node/.travis.yml
-
94govue2/govue-js-src/node_modules/acorn-node/CHANGELOG.md
-
95govue2/govue-js-src/node_modules/acorn-node/LICENSE.md
-
65govue2/govue-js-src/node_modules/acorn-node/README.md
-
36govue2/govue-js-src/node_modules/acorn-node/build.js
-
38govue2/govue-js-src/node_modules/acorn-node/index.js
-
71govue2/govue-js-src/node_modules/acorn-node/lib/bigint/index.js
-
70govue2/govue-js-src/node_modules/acorn-node/lib/class-fields/index.js
-
86govue2/govue-js-src/node_modules/acorn-node/lib/dynamic-import/index.js
-
43govue2/govue-js-src/node_modules/acorn-node/lib/export-ns-from/index.js
-
55govue2/govue-js-src/node_modules/acorn-node/lib/import-meta/index.js
-
61govue2/govue-js-src/node_modules/acorn-node/lib/numeric-separator/index.js
-
135govue2/govue-js-src/node_modules/acorn-node/lib/private-class-elements/index.js
-
139govue2/govue-js-src/node_modules/acorn-node/lib/static-class-features/index.js
@ -1,11 +1,7 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="WEB_MODULE" version="4"> |
<module type="WEB_MODULE" version="4"> |
||||
<component name="Go" enabled="true" /> |
|
||||
<component name="NewModuleRootManager"> |
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
|
||||
<excludeFolder url="file://$MODULE_DIR$/govue-js-src" /> |
|
||||
<excludeFolder url="file://$MODULE_DIR$/govue/govue-js-src" /> |
|
||||
</content> |
|
||||
|
<content url="file://$MODULE_DIR$" /> |
||||
<orderEntry type="inheritedJdk" /> |
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
<orderEntry type="sourceFolder" forTests="false" /> |
||||
</component> |
</component> |
3238
.idea/workspace.xml
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
327
govue2/bindata.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,34 @@ |
|||||
|
package govue2 |
||||
|
|
||||
|
import ( |
||||
|
"sync" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
var cache sync.Map |
||||
|
|
||||
|
type mcache struct { |
||||
|
html string |
||||
|
creation int64 |
||||
|
timeoutSec int64 |
||||
|
} |
||||
|
|
||||
|
func GetCache(key string) string { |
||||
|
v, _ := cache.Load(key) |
||||
|
if v != nil { |
||||
|
mc := v.(*mcache) |
||||
|
if time.Now().Unix() < mc.creation+mc.timeoutSec { |
||||
|
//log.Println("加载缓存")
|
||||
|
return mc.html |
||||
|
} |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func SetCache(key string, val string, timeoutSec int64) { |
||||
|
cache.Store(key, &mcache{ |
||||
|
html: val, |
||||
|
creation: time.Now().Unix(), |
||||
|
timeoutSec: timeoutSec, |
||||
|
}) |
||||
|
} |
@ -0,0 +1,111 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"flag" |
||||
|
"fmt" |
||||
|
govue "git.ouxuan.net/3136352472/go-service-template/govue2" |
||||
|
"github.com/gin-gonic/gin" |
||||
|
"log" |
||||
|
"mime" |
||||
|
"path/filepath" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
|
||||
|
var addr string |
||||
|
var static string |
||||
|
var useFile string |
||||
|
var mode string |
||||
|
var path string |
||||
|
var errorPage404 string |
||||
|
|
||||
|
flag.StringVar(&path, "config", "govue.json", "配置文件路径") |
||||
|
|
||||
|
flag.StringVar(&static, "static", "", "静态文件目录") |
||||
|
|
||||
|
flag.StringVar(&addr, "addr", "", "监听ip:port") |
||||
|
|
||||
|
flag.StringVar(&mode, "mode", "", "模式release/debug") |
||||
|
|
||||
|
flag.StringVar(&errorPage404, "error_page_404", "", "404错误页面路径") |
||||
|
|
||||
|
flag.Parse() |
||||
|
|
||||
|
if flag.Arg(0) == "init" { |
||||
|
err := govue.GenerateConfig(path) |
||||
|
if err != nil { |
||||
|
fmt.Print("文件:", path, "\n生成失败:", err) |
||||
|
} else { |
||||
|
abs, _ := filepath.Abs(path) |
||||
|
fmt.Print("文件:", abs, "\n生成成功:") |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
config, err := govue.GetConfig(path) |
||||
|
fmt.Println("配置载入:", path) |
||||
|
fmt.Println("渲染协程池最大总数:", config.Pool.MaxTotal) |
||||
|
fmt.Println("渲染协程池最大空闲数:", config.Pool.MaxIdle) |
||||
|
fmt.Println("渲染协程池最小空闲数:", config.Pool.MinIdle) |
||||
|
if addr != "" { |
||||
|
config.Addr = addr |
||||
|
} |
||||
|
if static != "" { |
||||
|
config.StaticDir = static |
||||
|
} |
||||
|
if useFile != "" { |
||||
|
config.UseJsFile = useFile |
||||
|
} |
||||
|
if mode != "" { |
||||
|
config.Mode = mode |
||||
|
} |
||||
|
|
||||
|
gin.SetMode(config.Mode) |
||||
|
r := gin.Default() |
||||
|
|
||||
|
govue.SetPoolConfig(config.Pool) |
||||
|
|
||||
|
gv, err := govue.NewGoVue(config.UseJsFile, config.StaticDir, config.Mode == "debug") |
||||
|
|
||||
|
if errorPage404 != "" { |
||||
|
config.ErrorPage404 = errorPage404 |
||||
|
} |
||||
|
gv.SetErrorPage404(config.ErrorPage404) |
||||
|
gv.SetCacheSec(5) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
|
||||
|
r.NoRoute(func(context *gin.Context) { |
||||
|
raw, err := gv.LoadStaticResources(context.Request) |
||||
|
if err != nil { |
||||
|
_, _ = context.Writer.Write(raw) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
mime.TypeByExtension(filepath.Ext(context.Request.URL.Path)) |
||||
|
ext := filepath.Ext(context.Request.URL.Path) |
||||
|
if ext == "" { |
||||
|
ext = ".html" |
||||
|
} |
||||
|
context.Writer.Header().Set("Content-Type", mime.TypeByExtension(ext)+"; charset=utf-8") |
||||
|
context.Writer.WriteHeader(200) |
||||
|
_, _ = context.Writer.Write(raw) |
||||
|
}) |
||||
|
|
||||
|
r.Use(func(context *gin.Context) { |
||||
|
context.Header("Access-Control-Allow-Origin", "*") |
||||
|
context.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") |
||||
|
context.Header("Access-Control-Allow-Headers", "Action, Module, X-PINGOTHER, Content-Type, Content-Disposition") |
||||
|
}) |
||||
|
|
||||
|
gv.StartPoolLog() |
||||
|
|
||||
|
for { |
||||
|
err = r.Run(config.Addr) |
||||
|
if err != nil { |
||||
|
log.Println("服务意外停止:", err) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
package govue2 |
||||
|
|
||||
|
import ( |
||||
|
"errors" |
||||
|
"git.ouxuan.net/3136352472/go-service-template/pool" |
||||
|
) |
||||
|
|
||||
|
type Config struct { |
||||
|
Addr string `json:"addr"` |
||||
|
StaticDir string `json:"static_dir"` |
||||
|
UseJsFile string `json:"use_js_file"` |
||||
|
ErrorPage404 string `json:"error_page_404"` |
||||
|
Mode string `json:"mode"` |
||||
|
Pool pool.Config `json:"pool"` |
||||
|
} |
||||
|
|
||||
|
func GenerateConfig(path string) (err error) { |
||||
|
if pathExists(path) { |
||||
|
err = errors.New("配置文件已存在") |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
config := Config{ |
||||
|
Addr: "0.0.0.0:8080", |
||||
|
StaticDir: "static", |
||||
|
UseJsFile: "static/use.js", |
||||
|
Mode: "release", |
||||
|
Pool: pool.Config{ |
||||
|
MaxIdle: 2000, |
||||
|
MinIdle: 5, |
||||
|
MaxTotal: 6000, |
||||
|
}, |
||||
|
} |
||||
|
jsonToFile(path, config) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func GetConfig(path string) (c *Config, err error) { |
||||
|
c = &Config{ |
||||
|
Addr: "0.0.0.0:8080", |
||||
|
StaticDir: "static", |
||||
|
UseJsFile: "static/use.js", |
||||
|
Mode: "release", |
||||
|
Pool: pool.Config{ |
||||
|
MaxIdle: 2000, |
||||
|
MinIdle: 5, |
||||
|
MaxTotal: 6000, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
if pathExists(path) { |
||||
|
jsonByFile(path, c) |
||||
|
} |
||||
|
|
||||
|
return |
||||
|
|
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
var fs = require("fs"); |
||||
|
var envify = require('envify/custom') |
||||
|
var browserify = require("browserify"); |
||||
|
browserify("./govue.js") |
||||
|
.transform({ global: true }, envify({ NODE_ENV: 'production' })) |
||||
|
.bundle() |
||||
|
.pipe(fs.createWriteStream("../govue-runtime/govue.js")); |
@ -0,0 +1,16 @@ |
|||||
|
|
||||
|
var process = { env: { VUE_ENV: "server", NODE_ENV: "production" } }; this.global = { process: process }; |
||||
|
Promise = require('es6-promise').Promise; |
||||
|
require('Vue'); |
||||
|
require('vue-router') |
||||
|
require('vue-server-renderer') |
||||
|
require('axios'); |
||||
|
require('qs'); |
||||
|
require('axios/lib/helpers/buildURL'); |
||||
|
require('axios/lib/core/buildFullPath'); |
||||
|
require('axios/lib/core/settle'); |
||||
|
require('axios/lib/core/createError'); |
||||
|
require("htmlparser2"); |
||||
|
GV.init = function(cb){ |
||||
|
cb(require) |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../JSONStream/bin.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../JSONStream/bin.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\JSONStream\bin.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../JSONStream/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../JSONStream/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../acorn/bin/acorn" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../acorn/bin/acorn" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\acorn\bin\acorn" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../acorn/bin/acorn" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../acorn/bin/acorn" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../browser-pack/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../browser-pack/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\browser-pack\bin\cmd.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../browser-pack/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../browser-pack/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../browserify/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../browserify/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\browserify\bin\cmd.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../browserify/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../browserify/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../deps-sort/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../deps-sort/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\deps-sort\bin\cmd.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../deps-sort/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../deps-sort/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../detective/bin/detective.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../detective/bin/detective.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\detective\bin\detective.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../detective/bin/detective.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../detective/bin/detective.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../envify/bin/envify" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../envify/bin/envify" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\envify\bin\envify" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../envify/bin/envify" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../envify/bin/envify" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../esprima/bin/esparse.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../esprima/bin/esparse.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\esprima\bin\esparse.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../esprima/bin/esparse.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../esprima/bin/esparse.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../esprima/bin/esvalidate.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../esprima/bin/esvalidate.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\esprima\bin\esvalidate.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../esprima/bin/esvalidate.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../esprima/bin/esvalidate.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../he/bin/he" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../he/bin/he" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\he\bin\he" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../he/bin/he" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../he/bin/he" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../insert-module-globals/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../insert-module-globals/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\insert-module-globals\bin\cmd.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../insert-module-globals/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../insert-module-globals/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../miller-rabin/bin/miller-rabin" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../miller-rabin/bin/miller-rabin" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\miller-rabin\bin\miller-rabin" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../miller-rabin/bin/miller-rabin" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../miller-rabin/bin/miller-rabin" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../module-deps/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../module-deps/bin/cmd.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\module-deps\bin\cmd.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../module-deps/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../module-deps/bin/cmd.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh
|
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../sha.js/bin.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../sha.js/bin.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\sha.js\bin.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../sha.js/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../sha.js/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../umd/bin/cli.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../umd/bin/cli.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\umd\bin\cli.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../umd/bin/cli.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../umd/bin/cli.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||
|
|
||||
|
case `uname` in |
||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||
|
esac |
||||
|
|
||||
|
if [ -x "$basedir/node" ]; then |
||||
|
"$basedir/node" "$basedir/../undeclared-identifiers/bin.js" "$@" |
||||
|
ret=$? |
||||
|
else |
||||
|
node "$basedir/../undeclared-identifiers/bin.js" "$@" |
||||
|
ret=$? |
||||
|
fi |
||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||
|
@ECHO off |
||||
|
SETLOCAL |
||||
|
CALL :find_dp0 |
||||
|
|
||||
|
IF EXIST "%dp0%\node.exe" ( |
||||
|
SET "_prog=%dp0%\node.exe" |
||||
|
) ELSE ( |
||||
|
SET "_prog=node" |
||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||
|
) |
||||
|
|
||||
|
"%_prog%" "%dp0%\..\undeclared-identifiers\bin.js" %* |
||||
|
ENDLOCAL |
||||
|
EXIT /b %errorlevel% |
||||
|
:find_dp0 |
||||
|
SET dp0=%~dp0 |
||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||
|
#!/usr/bin/env pwsh |
||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||
|
|
||||
|
$exe="" |
||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||
|
# Fix case when both the Windows and Linux builds of Node |
||||
|
# are installed in the same directory |
||||
|
$exe=".exe" |
||||
|
} |
||||
|
$ret=0 |
||||
|
if (Test-Path "$basedir/node$exe") { |
||||
|
& "$basedir/node$exe" "$basedir/../undeclared-identifiers/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} else { |
||||
|
& "node$exe" "$basedir/../undeclared-identifiers/bin.js" $args |
||||
|
$ret=$LASTEXITCODE |
||||
|
} |
||||
|
exit $ret |
@ -0,0 +1,8 @@ |
|||||
|
language: node_js |
||||
|
node_js: |
||||
|
- 4 |
||||
|
- 5 |
||||
|
- 6 |
||||
|
sudo: false |
||||
|
|
||||
|
|
@ -0,0 +1,15 @@ |
|||||
|
Apache License, Version 2.0 |
||||
|
|
||||
|
Copyright (c) 2011 Dominic Tarr |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
@ -0,0 +1,24 @@ |
|||||
|
The MIT License |
||||
|
|
||||
|
Copyright (c) 2011 Dominic Tarr |
||||
|
|
||||
|
Permission is hereby granted, free of charge, |
||||
|
to any person obtaining a copy of this software and |
||||
|
associated documentation files (the "Software"), to |
||||
|
deal in the Software without restriction, including |
||||
|
without limitation the rights to use, copy, modify, |
||||
|
merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom |
||||
|
the Software is furnished to do so, |
||||
|
subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice |
||||
|
shall be included in all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
||||
|
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,12 @@ |
|||||
|
#! /usr/bin/env node
|
||||
|
|
||||
|
var JSONStream = require('./') |
||||
|
|
||||
|
if(!module.parent && process.title !== 'browser') { |
||||
|
process.stdin |
||||
|
.pipe(JSONStream.parse(process.argv[2])) |
||||
|
.pipe(JSONStream.stringify('[', ',\n', ']\n', 2)) |
||||
|
.pipe(process.stdout) |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,13 @@ |
|||||
|
var request = require('request') |
||||
|
, JSONStream = require('JSONStream') |
||||
|
, es = require('event-stream') |
||||
|
|
||||
|
var parser = JSONStream.parse(['rows', true]) //emit parts that match this path (any element of the rows array)
|
||||
|
, req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'}) |
||||
|
, logger = es.mapSync(function (data) { //create a stream that logs to stderr,
|
||||
|
console.error(data) |
||||
|
return data |
||||
|
}) |
||||
|
|
||||
|
req.pipe(parser) |
||||
|
parser.pipe(logger) |
@ -0,0 +1,247 @@ |
|||||
|
'use strict' |
||||
|
|
||||
|
var Parser = require('jsonparse') |
||||
|
, through = require('through') |
||||
|
|
||||
|
var bufferFrom = Buffer.from && Buffer.from !== Uint8Array.from |
||||
|
|
||||
|
/* |
||||
|
|
||||
|
the value of this.stack that creationix's jsonparse has is weird. |
||||
|
|
||||
|
it makes this code ugly, but his problem is way harder that mine, |
||||
|
so i'll forgive him. |
||||
|
|
||||
|
*/ |
||||
|
|
||||
|
exports.parse = function (path, map) { |
||||
|
var header, footer |
||||
|
var parser = new Parser() |
||||
|
var stream = through(function (chunk) { |
||||
|
if('string' === typeof chunk) |
||||
|
chunk = bufferFrom ? Buffer.from(chunk) : new Buffer(chunk) |
||||
|
parser.write(chunk) |
||||
|
}, |
||||
|
function (data) { |
||||
|
if(data) |
||||
|
stream.write(data) |
||||
|
if (header) |
||||
|
stream.emit('header', header) |
||||
|
if (footer) |
||||
|
stream.emit('footer', footer) |
||||
|
stream.queue(null) |
||||
|
}) |
||||
|
|
||||
|
if('string' === typeof path) |
||||
|
path = path.split('.').map(function (e) { |
||||
|
if (e === '$*') |
||||
|
return {emitKey: true} |
||||
|
else if (e === '*') |
||||
|
return true |
||||
|
else if (e === '') // '..'.split('.') returns an empty string
|
||||
|
return {recurse: true} |
||||
|
else |
||||
|
return e |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
var count = 0, _key |
||||
|
if(!path || !path.length) |
||||
|
path = null |
||||
|
|
||||
|
parser.onValue = function (value) { |
||||
|
if (!this.root) |
||||
|
stream.root = value |
||||
|
|
||||
|
if(! path) return |
||||
|
|
||||
|
var i = 0 // iterates on path
|
||||
|
var j = 0 // iterates on stack
|
||||
|
var emitKey = false; |
||||
|
var emitPath = false; |
||||
|
while (i < path.length) { |
||||
|
var key = path[i] |
||||
|
var c |
||||
|
j++ |
||||
|
|
||||
|
if (key && !key.recurse) { |
||||
|
c = (j === this.stack.length) ? this : this.stack[j] |
||||
|
if (!c) return |
||||
|
if (! check(key, c.key)) { |
||||
|
setHeaderFooter(c.key, value) |
||||
|
return |
||||
|
} |
||||
|
emitKey = !!key.emitKey; |
||||
|
emitPath = !!key.emitPath; |
||||
|
i++ |
||||
|
} else { |
||||
|
i++ |
||||
|
var nextKey = path[i] |
||||
|
if (! nextKey) return |
||||
|
while (true) { |
||||
|
c = (j === this.stack.length) ? this : this.stack[j] |
||||
|
if (!c) return |
||||
|
if (check(nextKey, c.key)) { |
||||
|
i++; |
||||
|
if (!Object.isFrozen(this.stack[j])) |
||||
|
this.stack[j].value = null |
||||
|
break |
||||
|
} else { |
||||
|
setHeaderFooter(c.key, value) |
||||
|
} |
||||
|
j++ |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// emit header
|
||||
|
if (header) { |
||||
|
stream.emit('header', header); |
||||
|
header = false; |
||||
|
} |
||||
|
if (j !== this.stack.length) return |
||||
|
|
||||
|
count ++ |
||||
|
var actualPath = this.stack.slice(1).map(function(element) { return element.key }).concat([this.key]) |
||||
|
var data = value |
||||
|
if(null != data) |
||||
|
if(null != (data = map ? map(data, actualPath) : data)) { |
||||
|
if (emitKey || emitPath) { |
||||
|
data = { value: data }; |
||||
|
if (emitKey) |
||||
|
data["key"] = this.key; |
||||
|
if (emitPath) |
||||
|
data["path"] = actualPath; |
||||
|
} |
||||
|
|
||||
|
stream.queue(data) |
||||
|
} |
||||
|
if (this.value) delete this.value[this.key] |
||||
|
for(var k in this.stack) |
||||
|
if (!Object.isFrozen(this.stack[k])) |
||||
|
this.stack[k].value = null |
||||
|
} |
||||
|
parser._onToken = parser.onToken; |
||||
|
|
||||
|
parser.onToken = function (token, value) { |
||||
|
parser._onToken(token, value); |
||||
|
if (this.stack.length === 0) { |
||||
|
if (stream.root) { |
||||
|
if(!path) |
||||
|
stream.queue(stream.root) |
||||
|
count = 0; |
||||
|
stream.root = null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
parser.onError = function (err) { |
||||
|
if(err.message.indexOf("at position") > -1) |
||||
|
err.message = "Invalid JSON (" + err.message + ")"; |
||||
|
stream.emit('error', err) |
||||
|
} |
||||
|
|
||||
|
return stream |
||||
|
|
||||
|
function setHeaderFooter(key, value) { |
||||
|
// header has not been emitted yet
|
||||
|
if (header !== false) { |
||||
|
header = header || {} |
||||
|
header[key] = value |
||||
|
} |
||||
|
|
||||
|
// footer has not been emitted yet but header has
|
||||
|
if (footer !== false && header === false) { |
||||
|
footer = footer || {} |
||||
|
footer[key] = value |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function check (x, y) { |
||||
|
if ('string' === typeof x) |
||||
|
return y == x |
||||
|
else if (x && 'function' === typeof x.exec) |
||||
|
return x.exec(y) |
||||
|
else if ('boolean' === typeof x || 'object' === typeof x) |
||||
|
return x |
||||
|
else if ('function' === typeof x) |
||||
|
return x(y) |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
exports.stringify = function (op, sep, cl, indent) { |
||||
|
indent = indent || 0 |
||||
|
if (op === false){ |
||||
|
op = '' |
||||
|
sep = '\n' |
||||
|
cl = '' |
||||
|
} else if (op == null) { |
||||
|
|
||||
|
op = '[\n' |
||||
|
sep = '\n,\n' |
||||
|
cl = '\n]\n' |
||||
|
|
||||
|
} |
||||
|
|
||||
|
//else, what ever you like
|
||||
|
|
||||
|
var stream |
||||
|
, first = true |
||||
|
, anyData = false |
||||
|
stream = through(function (data) { |
||||
|
anyData = true |
||||
|
try { |
||||
|
var json = JSON.stringify(data, null, indent) |
||||
|
} catch (err) { |
||||
|
return stream.emit('error', err) |
||||
|
} |
||||
|
if(first) { first = false ; stream.queue(op + json)} |
||||
|
else stream.queue(sep + json) |
||||
|
}, |
||||
|
function (data) { |
||||
|
if(!anyData) |
||||
|
stream.queue(op) |
||||
|
stream.queue(cl) |
||||
|
stream.queue(null) |
||||
|
}) |
||||
|
|
||||
|
return stream |
||||
|
} |
||||
|
|
||||
|
exports.stringifyObject = function (op, sep, cl, indent) { |
||||
|
indent = indent || 0 |
||||
|
if (op === false){ |
||||
|
op = '' |
||||
|
sep = '\n' |
||||
|
cl = '' |
||||
|
} else if (op == null) { |
||||
|
|
||||
|
op = '{\n' |
||||
|
sep = '\n,\n' |
||||
|
cl = '\n}\n' |
||||
|
|
||||
|
} |
||||
|
|
||||
|
//else, what ever you like
|
||||
|
|
||||
|
var first = true |
||||
|
var anyData = false |
||||
|
var stream = through(function (data) { |
||||
|
anyData = true |
||||
|
var json = JSON.stringify(data[0]) + ':' + JSON.stringify(data[1], null, indent) |
||||
|
if(first) { first = false ; this.queue(op + json)} |
||||
|
else this.queue(sep + json) |
||||
|
}, |
||||
|
function (data) { |
||||
|
if(!anyData) this.queue(op) |
||||
|
this.queue(cl) |
||||
|
|
||||
|
this.queue(null) |
||||
|
}) |
||||
|
|
||||
|
return stream |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,207 @@ |
|||||
|
# JSONStream |
||||
|
|
||||
|
streaming JSON.parse and stringify |
||||
|
|
||||
|
![](https://secure.travis-ci.org/dominictarr/JSONStream.png?branch=master) |
||||
|
|
||||
|
## install |
||||
|
```npm install JSONStream``` |
||||
|
|
||||
|
## example |
||||
|
|
||||
|
``` js |
||||
|
|
||||
|
var request = require('request') |
||||
|
, JSONStream = require('JSONStream') |
||||
|
, es = require('event-stream') |
||||
|
|
||||
|
request({url: 'http://isaacs.couchone.com/registry/_all_docs'}) |
||||
|
.pipe(JSONStream.parse('rows.*')) |
||||
|
.pipe(es.mapSync(function (data) { |
||||
|
console.error(data) |
||||
|
return data |
||||
|
})) |
||||
|
``` |
||||
|
|
||||
|
## JSONStream.parse(path) |
||||
|
|
||||
|
parse stream of values that match a path |
||||
|
|
||||
|
``` js |
||||
|
JSONStream.parse('rows.*.doc') |
||||
|
``` |
||||
|
|
||||
|
The `..` operator is the recursive descent operator from [JSONPath](http://goessner.net/articles/JsonPath/), which will match a child at any depth (see examples below). |
||||
|
|
||||
|
If your keys have keys that include `.` or `*` etc, use an array instead. |
||||
|
`['row', true, /^doc/]`. |
||||
|
|
||||
|
If you use an array, `RegExp`s, booleans, and/or functions. The `..` operator is also available in array representation, using `{recurse: true}`. |
||||
|
any object that matches the path will be emitted as 'data' (and `pipe`d down stream) |
||||
|
|
||||
|
If `path` is empty or null, no 'data' events are emitted. |
||||
|
|
||||
|
If you want to have keys emitted, you can prefix your `*` operator with `$`: `obj.$*` - in this case the data passed to the stream is an object with a `key` holding the key and a `value` property holding the data. |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
query a couchdb view: |
||||
|
|
||||
|
``` bash |
||||
|
curl -sS localhost:5984/tests/_all_docs&include_docs=true |
||||
|
``` |
||||
|
you will get something like this: |
||||
|
|
||||
|
``` js |
||||
|
{"total_rows":129,"offset":0,"rows":[ |
||||
|
{ "id":"change1_0.6995461115147918" |
||||
|
, "key":"change1_0.6995461115147918" |
||||
|
, "value":{"rev":"1-e240bae28c7bb3667f02760f6398d508"} |
||||
|
, "doc":{ |
||||
|
"_id": "change1_0.6995461115147918" |
||||
|
, "_rev": "1-e240bae28c7bb3667f02760f6398d508","hello":1} |
||||
|
}, |
||||
|
{ "id":"change2_0.6995461115147918" |
||||
|
, "key":"change2_0.6995461115147918" |
||||
|
, "value":{"rev":"1-13677d36b98c0c075145bb8975105153"} |
||||
|
, "doc":{ |
||||
|
"_id":"change2_0.6995461115147918" |
||||
|
, "_rev":"1-13677d36b98c0c075145bb8975105153" |
||||
|
, "hello":2 |
||||
|
} |
||||
|
}, |
||||
|
]} |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
we are probably most interested in the `rows.*.doc` |
||||
|
|
||||
|
create a `Stream` that parses the documents from the feed like this: |
||||
|
|
||||
|
``` js |
||||
|
var stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc |
||||
|
|
||||
|
stream.on('data', function(data) { |
||||
|
console.log('received:', data); |
||||
|
}); |
||||
|
//emits anything from _before_ the first match |
||||
|
stream.on('header', function (data) { |
||||
|
console.log('header:', data) // => {"total_rows":129,"offset":0} |
||||
|
}) |
||||
|
|
||||
|
``` |
||||
|
awesome! |
||||
|
|
||||
|
In case you wanted the contents the doc emitted: |
||||
|
|
||||
|
``` js |
||||
|
var stream = JSONStream.parse(['rows', true, 'doc', {emitKey: true}]) //rows, ANYTHING, doc, items in docs with keys |
||||
|
|
||||
|
stream.on('data', function(data) { |
||||
|
console.log('key:', data.key); |
||||
|
console.log('value:', data.value); |
||||
|
}); |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
You can also emit the path: |
||||
|
|
||||
|
``` js |
||||
|
var stream = JSONStream.parse(['rows', true, 'doc', {emitPath: true}]) //rows, ANYTHING, doc, items in docs with keys |
||||
|
|
||||
|
stream.on('data', function(data) { |
||||
|
console.log('path:', data.path); |
||||
|
console.log('value:', data.value); |
||||
|
}); |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### recursive patterns (..) |
||||
|
|
||||
|
`JSONStream.parse('docs..value')` |
||||
|
(or `JSONStream.parse(['docs', {recurse: true}, 'value'])` using an array) |
||||
|
will emit every `value` object that is a child, grand-child, etc. of the |
||||
|
`docs` object. In this example, it will match exactly 5 times at various depth |
||||
|
levels, emitting 0, 1, 2, 3 and 4 as results. |
||||
|
|
||||
|
```js |
||||
|
{ |
||||
|
"total": 5, |
||||
|
"docs": [ |
||||
|
{ |
||||
|
"key": { |
||||
|
"value": 0, |
||||
|
"some": "property" |
||||
|
} |
||||
|
}, |
||||
|
{"value": 1}, |
||||
|
{"value": 2}, |
||||
|
{"blbl": [{}, {"a":0, "b":1, "value":3}, 10]}, |
||||
|
{"value": 4} |
||||
|
] |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## JSONStream.parse(pattern, map) |
||||
|
|
||||
|
provide a function that can be used to map or filter |
||||
|
the json output. `map` is passed the value at that node of the pattern, |
||||
|
if `map` return non-nullish (anything but `null` or `undefined`) |
||||
|
that value will be emitted in the stream. If it returns a nullish value, |
||||
|
nothing will be emitted. |
||||
|
|
||||
|
`JSONStream` also emits `'header'` and `'footer'` events, |
||||
|
the `'header'` event contains anything in the output that was before |
||||
|
the first match, and the `'footer'`, is anything after the last match. |
||||
|
|
||||
|
## JSONStream.stringify(open, sep, close) |
||||
|
|
||||
|
Create a writable stream. |
||||
|
|
||||
|
you may pass in custom `open`, `close`, and `seperator` strings. |
||||
|
But, by default, `JSONStream.stringify()` will create an array, |
||||
|
(with default options `open='[\n', sep='\n,\n', close='\n]\n'`) |
||||
|
|
||||
|
If you call `JSONStream.stringify(false)` |
||||
|
the elements will only be seperated by a newline. |
||||
|
|
||||
|
If you only write one item this will be valid JSON. |
||||
|
|
||||
|
If you write many items, |
||||
|
you can use a `RegExp` to split it into valid chunks. |
||||
|
|
||||
|
## JSONStream.stringifyObject(open, sep, close) |
||||
|
|
||||
|
Very much like `JSONStream.stringify`, |
||||
|
but creates a writable stream for objects instead of arrays. |
||||
|
|
||||
|
Accordingly, `open='{\n', sep='\n,\n', close='\n}\n'`. |
||||
|
|
||||
|
When you `.write()` to the stream you must supply an array with `[ key, data ]` |
||||
|
as the first argument. |
||||
|
|
||||
|
## unix tool |
||||
|
|
||||
|
query npm to see all the modules that browserify has ever depended on. |
||||
|
|
||||
|
``` bash |
||||
|
curl https://registry.npmjs.org/browserify | JSONStream 'versions.*.dependencies' |
||||
|
``` |
||||
|
|
||||
|
## numbers |
||||
|
|
||||
|
numbers will be emitted as numbers. |
||||
|
huge numbers that cannot be represented in memory as javascript numbers will be emitted as strings. |
||||
|
cf https://github.com/creationix/jsonparse/commit/044b268f01c4b8f97fb936fc85d3bcfba179e5bb for details. |
||||
|
|
||||
|
## Acknowlegements |
||||
|
|
||||
|
this module depends on https://github.com/creationix/jsonparse |
||||
|
by Tim Caswell |
||||
|
and also thanks to Florent Jaby for teaching me about parsing with: |
||||
|
https://github.com/Floby/node-json-streams |
||||
|
|
||||
|
## license |
||||
|
|
||||
|
Dual-licensed under the MIT License or the Apache License, version 2.0 |
||||
|
|
@ -0,0 +1,41 @@ |
|||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is').style('colour') |
||||
|
|
||||
|
function randomObj () { |
||||
|
return ( |
||||
|
Math.random () < 0.4 |
||||
|
? {hello: 'eonuhckmqjk', |
||||
|
whatever: 236515, |
||||
|
lies: true, |
||||
|
nothing: [null], |
||||
|
// stuff: [Math.random(),Math.random(),Math.random()]
|
||||
|
} |
||||
|
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
var expected = [] |
||||
|
, stringify = JSONStream.stringify() |
||||
|
, es = require('event-stream') |
||||
|
, stringified = '' |
||||
|
, called = 0 |
||||
|
, count = 10 |
||||
|
, ended = false |
||||
|
|
||||
|
while (count --) |
||||
|
expected.push(randomObj()) |
||||
|
|
||||
|
es.connect( |
||||
|
es.readArray(expected), |
||||
|
stringify, |
||||
|
JSONStream.parse([true]), |
||||
|
es.writeArray(function (err, lines) { |
||||
|
|
||||
|
it(lines).has(expected) |
||||
|
console.error('PASSED') |
||||
|
}) |
||||
|
) |
@ -0,0 +1,18 @@ |
|||||
|
var test = require('tape') |
||||
|
var JSONStream = require('../') |
||||
|
var testData = '{"rows":[{"hello":"world"}, {"foo": "bar"}]}' |
||||
|
|
||||
|
test('basic parsing', function (t) { |
||||
|
t.plan(2) |
||||
|
var parsed = JSONStream.parse("rows.*") |
||||
|
var parsedKeys = {} |
||||
|
parsed.on('data', function(match) { |
||||
|
parsedKeys[Object.keys(match)[0]] = true |
||||
|
}) |
||||
|
parsed.on('end', function() { |
||||
|
t.equal(!!parsedKeys['hello'], true) |
||||
|
t.equal(!!parsedKeys['foo'], true) |
||||
|
}) |
||||
|
parsed.write(testData) |
||||
|
parsed.end() |
||||
|
}) |
@ -0,0 +1,27 @@ |
|||||
|
var fs = require ('fs'); |
||||
|
var net = require('net'); |
||||
|
var join = require('path').join; |
||||
|
var file = join(__dirname, 'fixtures','all_npm.json'); |
||||
|
var JSONStream = require('../'); |
||||
|
|
||||
|
|
||||
|
var server = net.createServer(function(client) { |
||||
|
var parser = JSONStream.parse([]); |
||||
|
parser.on('end', function() { |
||||
|
console.log('close') |
||||
|
console.error('PASSED'); |
||||
|
server.close(); |
||||
|
}); |
||||
|
client.pipe(parser); |
||||
|
var n = 4 |
||||
|
client.on('data', function () { |
||||
|
if(--n) return |
||||
|
client.end(); |
||||
|
}) |
||||
|
}); |
||||
|
server.listen(9999); |
||||
|
|
||||
|
|
||||
|
var client = net.connect({ port : 9999 }, function() { |
||||
|
fs.createReadStream(file).pipe(client).on('data', console.log) //.resume();
|
||||
|
}); |
@ -0,0 +1,29 @@ |
|||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse('rows..rev') |
||||
|
, called = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(expected.rows.length) |
||||
|
for (var i = 0 ; i < expected.rows.length ; i++) |
||||
|
it(parsed[i]).deepEqual(expected.rows[i].value.rev) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,30 @@ |
|||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','depth.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse(['docs', {recurse: true}, 'value']) |
||||
|
, called = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
var expectedValues = [0, [1], {"a": 2}, "3", 4] |
||||
|
it(called).equal(expectedValues.length) |
||||
|
for (var i = 0 ; i < 5 ; i++) |
||||
|
it(parsed[i]).deepEqual(expectedValues[i]) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,44 @@ |
|||||
|
var JSONStream = require('../') |
||||
|
, stream = require('stream') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var output = [ [], [] ] |
||||
|
|
||||
|
var parser1 = JSONStream.parse(['docs', /./]) |
||||
|
parser1.on('data', function(data) { |
||||
|
output[0].push(data) |
||||
|
}) |
||||
|
|
||||
|
var parser2 = JSONStream.parse(['docs', /./]) |
||||
|
parser2.on('data', function(data) { |
||||
|
output[1].push(data) |
||||
|
}) |
||||
|
|
||||
|
var pending = 2 |
||||
|
function onend () { |
||||
|
if (--pending > 0) return |
||||
|
it(output).deepEqual([ |
||||
|
[], [{hello: 'world'}] |
||||
|
]) |
||||
|
console.error('PASSED') |
||||
|
} |
||||
|
parser1.on('end', onend) |
||||
|
parser2.on('end', onend) |
||||
|
|
||||
|
function makeReadableStream() { |
||||
|
var readStream = new stream.Stream() |
||||
|
readStream.readable = true |
||||
|
readStream.write = function (data) { this.emit('data', data) } |
||||
|
readStream.end = function (data) { this.emit('end') } |
||||
|
return readStream |
||||
|
} |
||||
|
|
||||
|
var emptyArray = makeReadableStream() |
||||
|
emptyArray.pipe(parser1) |
||||
|
emptyArray.write('{"docs":[]}') |
||||
|
emptyArray.end() |
||||
|
|
||||
|
var objectArray = makeReadableStream() |
||||
|
objectArray.pipe(parser2) |
||||
|
objectArray.write('{"docs":[{"hello":"world"}]}') |
||||
|
objectArray.end() |
@ -0,0 +1,45 @@ |
|||||
|
|
||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','error.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse(['rows']) |
||||
|
, called = 0 |
||||
|
, headerCalled = 0 |
||||
|
, footerCalled = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('header', function (data) { |
||||
|
headerCalled ++ |
||||
|
it(data).deepEqual({ |
||||
|
error: 'error_code', |
||||
|
message: 'this is an error message' |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
parser.on('footer', function (data) { |
||||
|
footerCalled ++ |
||||
|
}) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(0) |
||||
|
it(headerCalled).equal(1) |
||||
|
it(footerCalled).equal(0) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,39 @@ |
|||||
|
|
||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
function fn (s) { |
||||
|
return !isNaN(parseInt(s, 10)) |
||||
|
} |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse(['rows', fn]) |
||||
|
, called = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
it.has({ |
||||
|
id: it.typeof('string'), |
||||
|
value: {rev: it.typeof('string')}, |
||||
|
key:it.typeof('string') |
||||
|
}) |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(expected.rows.length) |
||||
|
it(parsed).deepEqual(expected.rows) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,135 @@ |
|||||
|
return // dont run this test for now since tape is weird and broken on 0.10
|
||||
|
|
||||
|
var fs = require('fs') |
||||
|
var JSONStream = require('../') |
||||
|
var file = process.argv[2] || '/tmp/JSONStream-test-large.json' |
||||
|
var size = Number(process.argv[3] || 100000) |
||||
|
var tape = require('tape') |
||||
|
// if (process.title !== 'browser') {
|
||||
|
tape('out of mem', function (t) { |
||||
|
t.plan(1) |
||||
|
//////////////////////////////////////////////////////
|
||||
|
// Produces a random number between arg1 and arg2
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
var randomNumber = function (min, max) { |
||||
|
var number = Math.floor(Math.random() * (max - min + 1) + min); |
||||
|
return number; |
||||
|
}; |
||||
|
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
// Produces a random string of a length between arg1 and arg2
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
var randomString = function (min, max) { |
||||
|
|
||||
|
// add several spaces to increase chanses of creating 'words'
|
||||
|
var chars = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
||||
|
var result = ''; |
||||
|
|
||||
|
var randomLength = randomNumber(min, max); |
||||
|
|
||||
|
for (var i = randomLength; i > 0; --i) { |
||||
|
result += chars[Math.round(Math.random() * (chars.length - 1))]; |
||||
|
} |
||||
|
return result; |
||||
|
}; |
||||
|
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
// Produces a random JSON document, as a string
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
var randomJsonDoc = function () { |
||||
|
|
||||
|
var doc = { |
||||
|
"CrashOccurenceID": randomNumber(10000, 50000), |
||||
|
"CrashID": randomNumber(1000, 10000), |
||||
|
"SiteName": randomString(10, 25), |
||||
|
"MachineName": randomString(10, 25), |
||||
|
"Date": randomString(26, 26), |
||||
|
"ProcessDuration": randomString(18, 18), |
||||
|
"ThreadIdentityName": null, |
||||
|
"WindowsIdentityName": randomString(15, 40), |
||||
|
"OperatingSystemName": randomString(35, 65), |
||||
|
"DetailedExceptionInformation": randomString(100, 800) |
||||
|
}; |
||||
|
|
||||
|
doc = JSON.stringify(doc); |
||||
|
doc = doc.replace(/\,/g, ',\n'); // add new lines after each attribute
|
||||
|
return doc; |
||||
|
}; |
||||
|
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
// generates test data
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
var generateTestData = function (cb) { |
||||
|
|
||||
|
console.log('generating large data file...'); |
||||
|
|
||||
|
var stream = fs.createWriteStream(file, { |
||||
|
encoding: 'utf8' |
||||
|
}); |
||||
|
|
||||
|
var i = 0; |
||||
|
var max = size; |
||||
|
var writing = false |
||||
|
var split = ',\n'; |
||||
|
var doc = randomJsonDoc(); |
||||
|
stream.write('['); |
||||
|
|
||||
|
function write () { |
||||
|
if(writing) return |
||||
|
writing = true |
||||
|
while(++i < max) { |
||||
|
if(Math.random() < 0.001) |
||||
|
console.log('generate..', i + ' / ' + size) |
||||
|
if(!stream.write(doc + split)) { |
||||
|
writing = false |
||||
|
return stream.once('drain', write) |
||||
|
} |
||||
|
} |
||||
|
stream.write(doc + ']') |
||||
|
stream.end(); |
||||
|
console.log('END') |
||||
|
} |
||||
|
write() |
||||
|
stream.on('close', cb) |
||||
|
}; |
||||
|
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
// Shows that parsing 100000 instances using JSONStream fails
|
||||
|
//
|
||||
|
// After several seconds, you will get this crash
|
||||
|
// FATAL ERROR: JS Allocation failed - process out of memory
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
var testJSONStreamParse_causesOutOfMem = function (done) { |
||||
|
var items = 0 |
||||
|
console.log('parsing data files using JSONStream...'); |
||||
|
|
||||
|
var parser = JSONStream.parse([true]); |
||||
|
var stream = fs.createReadStream(file); |
||||
|
stream.pipe(parser); |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
items++ |
||||
|
if(Math.random() < 0.01) console.log(items, '...') |
||||
|
}); |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
t.equal(items, size) |
||||
|
}); |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
// main
|
||||
|
//////////////////////////////////////////////////////
|
||||
|
|
||||
|
fs.stat(file, function (err, stat) { |
||||
|
console.log(stat) |
||||
|
if(err) |
||||
|
generateTestData(testJSONStreamParse_causesOutOfMem); |
||||
|
else |
||||
|
testJSONStreamParse_causesOutOfMem() |
||||
|
}) |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
// }
|
@ -0,0 +1,55 @@ |
|||||
|
|
||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','header_footer.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse(['rows', /\d+/ /*, 'value'*/]) |
||||
|
, called = 0 |
||||
|
, headerCalled = 0 |
||||
|
, footerCalled = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('header', function (data) { |
||||
|
headerCalled ++ |
||||
|
it(data).deepEqual({ |
||||
|
total_rows: 129, |
||||
|
offset: 0 |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
parser.on('footer', function (data) { |
||||
|
footerCalled ++ |
||||
|
it(data).deepEqual({ |
||||
|
foo: { bar: 'baz' } |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
it.has({ |
||||
|
id: it.typeof('string'), |
||||
|
value: {rev: it.typeof('string')}, |
||||
|
key:it.typeof('string') |
||||
|
}) |
||||
|
it(headerCalled).equal(1) |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(expected.rows.length) |
||||
|
it(headerCalled).equal(1) |
||||
|
it(footerCalled).equal(1) |
||||
|
it(parsed).deepEqual(expected.rows) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,34 @@ |
|||||
|
var JSONStream = require('../'); |
||||
|
var test = require('tape') |
||||
|
|
||||
|
test('#66', function (t) { |
||||
|
var error = 0; |
||||
|
var stream = JSONStream |
||||
|
.parse() |
||||
|
.on('error', function (err) { |
||||
|
t.ok(err); |
||||
|
error++; |
||||
|
}) |
||||
|
.on('end', function () { |
||||
|
t.ok(error === 1); |
||||
|
t.end(); |
||||
|
}); |
||||
|
|
||||
|
stream.write('["foo":bar['); |
||||
|
stream.end(); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
test('#81 - failure to parse nested objects', function (t) { |
||||
|
var stream = JSONStream |
||||
|
.parse('.bar.foo') |
||||
|
.on('error', function (err) { |
||||
|
t.error(err); |
||||
|
}) |
||||
|
.on('end', function () { |
||||
|
t.end(); |
||||
|
}); |
||||
|
|
||||
|
stream.write('{"bar":{"foo":"baz"}}'); |
||||
|
stream.end(); |
||||
|
}); |
@ -0,0 +1,105 @@ |
|||||
|
var test = require('tape'); |
||||
|
var fs = require ('fs'); |
||||
|
var join = require('path').join; |
||||
|
var couch_sample_file = join(__dirname, 'fixtures','couch_sample.json'); |
||||
|
var JSONStream = require('../'); |
||||
|
|
||||
|
var fixture = { |
||||
|
obj: { |
||||
|
one: 1, |
||||
|
two: 2, |
||||
|
three: 3 |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
function assertFixtureKeys(stream, t) { |
||||
|
var keys = []; |
||||
|
var values = []; |
||||
|
stream.on('data', function(data) { |
||||
|
keys.push(data.key); |
||||
|
values.push(data.value); |
||||
|
}); |
||||
|
|
||||
|
stream.on('end', function() { |
||||
|
t.deepEqual(keys, ['one', 'two', 'three']); |
||||
|
t.deepEqual(values, [1,2,3]); |
||||
|
t.end(); |
||||
|
}); |
||||
|
stream.write(JSON.stringify(fixture)); |
||||
|
stream.end(); |
||||
|
} |
||||
|
|
||||
|
test('keys via string', function(t) { |
||||
|
var stream = JSONStream.parse('obj.$*'); |
||||
|
assertFixtureKeys(stream, t); |
||||
|
}); |
||||
|
|
||||
|
test('keys via array', function(t) { |
||||
|
var stream = JSONStream.parse(['obj',{emitKey: true}]); |
||||
|
assertFixtureKeys(stream, t); |
||||
|
}); |
||||
|
|
||||
|
test('path via array', function(t) { |
||||
|
var stream = JSONStream.parse(['obj',{emitPath: true}]); |
||||
|
|
||||
|
var paths = []; |
||||
|
var values = []; |
||||
|
stream.on('data', function(data) { |
||||
|
console.log(JSON.stringify(data)); |
||||
|
paths.push(data.path); |
||||
|
values.push(data.value); |
||||
|
}); |
||||
|
|
||||
|
stream.on('end', function() { |
||||
|
t.deepEqual(paths, [['obj', 'one'], ['obj', 'two'], ['obj', 'three']]); |
||||
|
t.deepEqual(values, [1,2,3]); |
||||
|
t.end(); |
||||
|
}); |
||||
|
stream.write(JSON.stringify(fixture)); |
||||
|
stream.end(); |
||||
|
}); |
||||
|
|
||||
|
test('advanced keys', function(t) { |
||||
|
var advanced = fs.readFileSync(couch_sample_file); |
||||
|
var stream = JSONStream.parse(['rows', true, 'doc', {emitKey: true}]); |
||||
|
|
||||
|
var keys = []; |
||||
|
var values = []; |
||||
|
stream.on('data', function(data) { |
||||
|
keys.push(data.key); |
||||
|
values.push(data.value); |
||||
|
}); |
||||
|
|
||||
|
stream.on('end', function() { |
||||
|
t.deepEqual(keys, [ |
||||
|
'_id', '_rev', 'hello', |
||||
|
'_id', '_rev', 'hello' |
||||
|
]); |
||||
|
t.deepEqual(values, [ |
||||
|
"change1_0.6995461115147918", "1-e240bae28c7bb3667f02760f6398d508", 1, |
||||
|
"change2_0.6995461115147918", "1-13677d36b98c0c075145bb8975105153", 2 |
||||
|
]); |
||||
|
t.end(); |
||||
|
}); |
||||
|
stream.write(advanced); |
||||
|
stream.end(); |
||||
|
}); |
||||
|
|
||||
|
test('parent keys', function(t) { |
||||
|
var stream = JSONStream.parse('$*'); |
||||
|
var d = null; |
||||
|
stream.on('data', function(data) { |
||||
|
if(d) t.fail('should only be called once'); |
||||
|
d = data; |
||||
|
}); |
||||
|
|
||||
|
stream.on('end', function() { |
||||
|
t.deepEqual(d,{ |
||||
|
key: 'obj', |
||||
|
value: fixture.obj |
||||
|
}); |
||||
|
t.end(); |
||||
|
}); |
||||
|
stream.write(JSON.stringify(fixture)); |
||||
|
stream.end(); |
||||
|
}) |
@ -0,0 +1,40 @@ |
|||||
|
|
||||
|
var test = require('tape') |
||||
|
|
||||
|
var JSONStream = require('../') |
||||
|
|
||||
|
test('map function', function (t) { |
||||
|
|
||||
|
var actual = [] |
||||
|
|
||||
|
stream = JSONStream.parse([true], function (e) { return e*10 }) |
||||
|
stream.on('data', function (v) { actual.push(v)}) |
||||
|
stream.on('end', function () { |
||||
|
t.deepEqual(actual, [10,20,30,40,50,60]) |
||||
|
t.end() |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
stream.write(JSON.stringify([1,2,3,4,5,6], null, 2)) |
||||
|
stream.end() |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
test('filter function', function (t) { |
||||
|
|
||||
|
var actual = [] |
||||
|
|
||||
|
stream = JSONStream |
||||
|
.parse([true], function (e) { return e%2 ? e : null}) |
||||
|
.on('data', function (v) { actual.push(v)}) |
||||
|
.on('end', function () { |
||||
|
t.deepEqual(actual, [1,3,5]) |
||||
|
t.end() |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
stream.write(JSON.stringify([1,2,3,4,5,6], null, 2)) |
||||
|
stream.end() |
||||
|
|
||||
|
}) |
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
var fs = require ('fs'); |
||||
|
var net = require('net'); |
||||
|
var join = require('path').join; |
||||
|
var file = join(__dirname, 'fixtures','all_npm.json'); |
||||
|
var it = require('it-is'); |
||||
|
var JSONStream = require('../'); |
||||
|
|
||||
|
var str = fs.readFileSync(file); |
||||
|
|
||||
|
var datas = {} |
||||
|
|
||||
|
var server = net.createServer(function(client) { |
||||
|
var data_calls = 0; |
||||
|
var parser = JSONStream.parse(['rows', true, 'key']); |
||||
|
parser.on('data', function(data) { |
||||
|
++ data_calls; |
||||
|
datas[data] = (datas[data] || 0) + 1 |
||||
|
it(data).typeof('string') |
||||
|
}); |
||||
|
|
||||
|
parser.on('end', function() { |
||||
|
console.log('END') |
||||
|
var min = Infinity |
||||
|
for (var d in datas) |
||||
|
min = min > datas[d] ? datas[d] : min |
||||
|
it(min).equal(3); |
||||
|
server.close(); |
||||
|
}); |
||||
|
client.pipe(parser); |
||||
|
}); |
||||
|
server.listen(9999); |
||||
|
|
||||
|
var client = net.connect({ port : 9999 }, function() { |
||||
|
var msgs = str + ' ' + str + '\n\n' + str |
||||
|
client.end(msgs); |
||||
|
}); |
@ -0,0 +1,29 @@ |
|||||
|
var fs = require ('fs'); |
||||
|
var net = require('net'); |
||||
|
var join = require('path').join; |
||||
|
var file = join(__dirname, 'fixtures','all_npm.json'); |
||||
|
var it = require('it-is'); |
||||
|
var JSONStream = require('../'); |
||||
|
|
||||
|
var str = fs.readFileSync(file); |
||||
|
|
||||
|
var server = net.createServer(function(client) { |
||||
|
var data_calls = 0; |
||||
|
var parser = JSONStream.parse(); |
||||
|
parser.on('error', function(err) { |
||||
|
console.log(err); |
||||
|
server.close(); |
||||
|
}); |
||||
|
|
||||
|
parser.on('end', function() { |
||||
|
console.log('END'); |
||||
|
server.close(); |
||||
|
}); |
||||
|
client.pipe(parser); |
||||
|
}); |
||||
|
server.listen(9999); |
||||
|
|
||||
|
var client = net.connect({ port : 9999 }, function() { |
||||
|
var msgs = str + '}'; |
||||
|
client.end(msgs); |
||||
|
}); |
@ -0,0 +1,28 @@ |
|||||
|
var JSONStream = require('../') |
||||
|
|
||||
|
var data = [ |
||||
|
{ID: 1, optional: null}, |
||||
|
{ID: 2, optional: null}, |
||||
|
{ID: 3, optional: 20}, |
||||
|
{ID: 4, optional: null}, |
||||
|
{ID: 5, optional: 'hello'}, |
||||
|
{ID: 6, optional: null} |
||||
|
] |
||||
|
|
||||
|
|
||||
|
var test = require('tape') |
||||
|
|
||||
|
test ('null properties', function (t) { |
||||
|
var actual = [] |
||||
|
var stream = |
||||
|
|
||||
|
JSONStream.parse('*.optional') |
||||
|
.on('data', function (v) { actual.push(v) }) |
||||
|
.on('end', function () { |
||||
|
t.deepEqual(actual, [20, 'hello']) |
||||
|
t.end() |
||||
|
}) |
||||
|
|
||||
|
stream.write(JSON.stringify(data, null, 2)) |
||||
|
stream.end() |
||||
|
}) |
@ -0,0 +1,29 @@ |
|||||
|
|
||||
|
|
||||
|
/* |
||||
|
sometimes jsonparse changes numbers slightly. |
||||
|
*/ |
||||
|
|
||||
|
var r = Math.random() |
||||
|
, Parser = require('jsonparse') |
||||
|
, p = new Parser() |
||||
|
, assert = require('assert') |
||||
|
, times = 20 |
||||
|
, bufferFrom = Buffer.from && Buffer.from !== Uint8Array.from |
||||
|
, str |
||||
|
|
||||
|
while (times --) { |
||||
|
|
||||
|
assert.equal(JSON.parse(JSON.stringify(r)), r, 'core JSON') |
||||
|
|
||||
|
p.onValue = function (v) { |
||||
|
console.error('parsed', v) |
||||
|
assert.equal(v,r) |
||||
|
} |
||||
|
console.error('correct', r) |
||||
|
str = JSON.stringify([r]) |
||||
|
p.write (bufferFrom ? Buffer.from(str) : new Buffer(str)) |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
var readdirSync = require('fs').readdirSync |
||||
|
var spawnSync = require('child_process').spawnSync |
||||
|
var extname = require('path').extname |
||||
|
|
||||
|
var files = readdirSync(__dirname) |
||||
|
files.forEach(function(file){ |
||||
|
if (extname(file) !== '.js' || file === 'run.js') |
||||
|
return |
||||
|
console.log(`*** ${file} ***`) |
||||
|
var result = spawnSync(process.argv0, [file], { stdio: 'inherit', cwd: __dirname} ) |
||||
|
if (result.status !== 0) |
||||
|
process.exit(result.status) |
||||
|
}) |
@ -0,0 +1,41 @@ |
|||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is').style('colour') |
||||
|
|
||||
|
function randomObj () { |
||||
|
return ( |
||||
|
Math.random () < 0.4 |
||||
|
? {hello: 'eonuhckmqjk', |
||||
|
whatever: 236515, |
||||
|
lies: true, |
||||
|
nothing: [null], |
||||
|
stuff: [Math.random(),Math.random(),Math.random()] |
||||
|
} |
||||
|
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
var expected = [] |
||||
|
, stringify = JSONStream.stringify() |
||||
|
, es = require('event-stream') |
||||
|
, stringified = '' |
||||
|
, called = 0 |
||||
|
, count = 10 |
||||
|
, ended = false |
||||
|
|
||||
|
while (count --) |
||||
|
expected.push(randomObj()) |
||||
|
|
||||
|
es.connect( |
||||
|
es.readArray(expected), |
||||
|
stringify, |
||||
|
//JSONStream.parse([/./]),
|
||||
|
es.writeArray(function (err, lines) { |
||||
|
|
||||
|
it(JSON.parse(lines.join(''))).deepEqual(expected) |
||||
|
console.error('PASSED') |
||||
|
}) |
||||
|
) |
@ -0,0 +1,47 @@ |
|||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is').style('colour') |
||||
|
, es = require('event-stream') |
||||
|
, pending = 10 |
||||
|
, passed = true |
||||
|
|
||||
|
function randomObj () { |
||||
|
return ( |
||||
|
Math.random () < 0.4 |
||||
|
? {hello: 'eonuhckmqjk', |
||||
|
whatever: 236515, |
||||
|
lies: true, |
||||
|
nothing: [null], |
||||
|
stuff: [Math.random(),Math.random(),Math.random()] |
||||
|
} |
||||
|
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
for (var ix = 0; ix < pending; ix++) (function (count) { |
||||
|
var expected = {} |
||||
|
, stringify = JSONStream.stringifyObject() |
||||
|
|
||||
|
es.connect( |
||||
|
stringify, |
||||
|
es.writeArray(function (err, lines) { |
||||
|
it(JSON.parse(lines.join(''))).deepEqual(expected) |
||||
|
if (--pending === 0) { |
||||
|
console.error('PASSED') |
||||
|
} |
||||
|
}) |
||||
|
) |
||||
|
|
||||
|
while (count --) { |
||||
|
var key = Math.random().toString(16).slice(2) |
||||
|
expected[key] = randomObj() |
||||
|
stringify.write([ key, expected[key] ]) |
||||
|
} |
||||
|
|
||||
|
process.nextTick(function () { |
||||
|
stringify.end() |
||||
|
}) |
||||
|
})(ix) |
@ -0,0 +1,35 @@ |
|||||
|
|
||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse(['rows', /\d+/ /*, 'value'*/]) |
||||
|
, called = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
it.has({ |
||||
|
id: it.typeof('string'), |
||||
|
value: {rev: it.typeof('string')}, |
||||
|
key:it.typeof('string') |
||||
|
}) |
||||
|
parsed.push(data) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(expected.rows.length) |
||||
|
it(parsed).deepEqual(expected.rows) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,29 @@ |
|||||
|
|
||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, '..','package.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is') |
||||
|
|
||||
|
var expected = JSON.parse(fs.readFileSync(file)) |
||||
|
, parser = JSONStream.parse([]) |
||||
|
, called = 0 |
||||
|
, ended = false |
||||
|
, parsed = [] |
||||
|
|
||||
|
fs.createReadStream(file).pipe(parser) |
||||
|
|
||||
|
parser.on('data', function (data) { |
||||
|
called ++ |
||||
|
it(data).deepEqual(expected) |
||||
|
}) |
||||
|
|
||||
|
parser.on('end', function () { |
||||
|
ended = true |
||||
|
}) |
||||
|
|
||||
|
process.on('exit', function () { |
||||
|
it(called).equal(1) |
||||
|
console.error('PASSED') |
||||
|
}) |
@ -0,0 +1,41 @@ |
|||||
|
|
||||
|
var fs = require ('fs') |
||||
|
, join = require('path').join |
||||
|
, file = join(__dirname, 'fixtures','all_npm.json') |
||||
|
, JSONStream = require('../') |
||||
|
, it = require('it-is').style('colour') |
||||
|
|
||||
|
function randomObj () { |
||||
|
return ( |
||||
|
Math.random () < 0.4 |
||||
|
? {hello: 'eonuhckmqjk', |
||||
|
whatever: 236515, |
||||
|
lies: true, |
||||
|
nothing: [null], |
||||
|
// stuff: [Math.random(),Math.random(),Math.random()]
|
||||
|
} |
||||
|
: ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]] |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
var expected = [] |
||||
|
, stringify = JSONStream.stringify() |
||||
|
, es = require('event-stream') |
||||
|
, stringified = '' |
||||
|
, called = 0 |
||||
|
, count = 10 |
||||
|
, ended = false |
||||
|
|
||||
|
while (count --) |
||||
|
expected.push(randomObj()) |
||||
|
|
||||
|
es.connect( |
||||
|
es.readArray(expected), |
||||
|
stringify, |
||||
|
JSONStream.parse([/./]), |
||||
|
es.writeArray(function (err, lines) { |
||||
|
|
||||
|
it(lines).has(expected) |
||||
|
console.error('PASSED') |
||||
|
}) |
||||
|
) |
@ -0,0 +1,22 @@ |
|||||
|
language: node_js |
||||
|
node_js: |
||||
|
- '12' |
||||
|
- '11' |
||||
|
- '10' |
||||
|
- '9' |
||||
|
- '8' |
||||
|
- '6' |
||||
|
- '4' |
||||
|
- '0.12' |
||||
|
- '0.10' |
||||
|
- '0.8' |
||||
|
- '0.6' |
||||
|
before_install: |
||||
|
- 'nvm install-latest-npm' |
||||
|
install: |
||||
|
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' |
||||
|
sudo: false |
||||
|
matrix: |
||||
|
fast_finish: true |
||||
|
allow_failures: |
||||
|
- node_js: "0.6" |
@ -0,0 +1,94 @@ |
|||||
|
# acorn-node change log |
||||
|
|
||||
|
All notable changes to this project will be documented in this file. |
||||
|
|
||||
|
This project adheres to [Semantic Versioning](http://semver.org/). |
||||
|
|
||||
|
## 1.8.2 |
||||
|
* Revert a breaking change in import.meta parsing. |
||||
|
|
||||
|
## 1.8.1 |
||||
|
* Fix crash in compiled private-class-elements code. |
||||
|
|
||||
|
## 1.8.0 |
||||
|
* Upgrade acorn to v7. |
||||
|
|
||||
|
For backwards compatibility, `acorn-node` still uses the `Import` node type for dynamic imports, _NOT_ `ImportExpression` like acorn v7 and estree. |
||||
|
* Add numeric separator support: |
||||
|
```js |
||||
|
var a = 10_000_000_000_000_000_000_000_000n; |
||||
|
``` |
||||
|
|
||||
|
## 1.7.0 |
||||
|
* Add class instance fields support: |
||||
|
```js |
||||
|
class X { |
||||
|
pub = 1; |
||||
|
#priv = 2; |
||||
|
} |
||||
|
``` |
||||
|
* Add class static fields support: |
||||
|
```js |
||||
|
class X { |
||||
|
static pub = 1; |
||||
|
static #priv = 2; |
||||
|
} |
||||
|
``` |
||||
|
* Add `export * as ns` support when `sourceType` is 'module': |
||||
|
```js |
||||
|
export * as ns from './ns.mjs'; |
||||
|
``` |
||||
|
|
||||
|
## 1.6.2 |
||||
|
|
||||
|
* Allow dynamic `import()` in scripts. |
||||
|
* Update minimum dependency versions, fixing a peerDependency warning. |
||||
|
* Add Node 10 and 11 to CI. |
||||
|
|
||||
|
## 1.6.1 |
||||
|
|
||||
|
* Update acorn-dynamic-import to v4. |
||||
|
|
||||
|
## 1.6.0 |
||||
|
|
||||
|
* Upgrade acorn to v6. |
||||
|
* Add bigint support. |
||||
|
|
||||
|
## 1.5.2 |
||||
|
|
||||
|
* Upgrade acorn to support optional catch binding in the AST walker. |
||||
|
|
||||
|
## 1.5.1 |
||||
|
|
||||
|
* Fix tests on Node <= 0.12. |
||||
|
|
||||
|
## 1.5.0 |
||||
|
|
||||
|
* Add tests for async iteration, optional catch binding, import.meta, |
||||
|
dynamic import, bigint (currently unsupported). |
||||
|
* Add import.meta support. (`sourceType: 'module'` only) |
||||
|
* Add dynamic import support. (`sourceType: 'module'` only) |
||||
|
* Fix optional catch binding support in the walker. |
||||
|
|
||||
|
## 1.4.0 |
||||
|
|
||||
|
* Upgrade acorn to 5.6, which supports optional catch bindings and other |
||||
|
new syntax features. |
||||
|
* Set ecmaVersion to 2019 to opt in to optional catch bindings etc. |
||||
|
|
||||
|
## 1.3.0 |
||||
|
|
||||
|
* Upgrade acorn to 5.4, which supports object spread and async iteration. |
||||
|
* Remove acorn5-object-spread plugin. |
||||
|
|
||||
|
## 1.2.0 |
||||
|
|
||||
|
* Expose `acorn/dist/walk` as `acorn-node/walk`. |
||||
|
|
||||
|
## 1.1.0 |
||||
|
|
||||
|
* Enable `allowHashBang` and `allowReturnOutsideFunction` by default. |
||||
|
|
||||
|
## 1.0.0 |
||||
|
|
||||
|
* Initial release. |
@ -0,0 +1,95 @@ |
|||||
|
# [Apache License 2.0](https://spdx.org/licenses/Apache-2.0) |
||||
|
|
||||
|
Copyright 2018 Renée Kooi <renee@kooi.me> |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
> http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
|
||||
|
## acorn-bigint |
||||
|
|
||||
|
The code in the `lib/bigint` folder is compiled from code licensed as MIT: |
||||
|
|
||||
|
> Copyright (C) 2017-2018 by Adrian Heine |
||||
|
> |
||||
|
> Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
> of this software and associated documentation files (the "Software"), to deal |
||||
|
> in the Software without restriction, including without limitation the rights |
||||
|
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
> copies of the Software, and to permit persons to whom the Software is |
||||
|
> furnished to do so, subject to the following conditions: |
||||
|
> |
||||
|
> The above copyright notice and this permission notice shall be included in |
||||
|
> all copies or substantial portions of the Software. |
||||
|
> |
||||
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
> THE SOFTWARE. |
||||
|
|
||||
|
Find the source code at https://github.com/acornjs/acorn-bigint. |
||||
|
|
||||
|
## acorn-import-meta |
||||
|
|
||||
|
The code in the `lib/import-meta` folder is compiled from code licensed as MIT: |
||||
|
|
||||
|
> Copyright (C) 2017-2018 by Adrian Heine |
||||
|
> |
||||
|
> Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
> of this software and associated documentation files (the "Software"), to deal |
||||
|
> in the Software without restriction, including without limitation the rights |
||||
|
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
> copies of the Software, and to permit persons to whom the Software is |
||||
|
> furnished to do so, subject to the following conditions: |
||||
|
> |
||||
|
> The above copyright notice and this permission notice shall be included in |
||||
|
> all copies or substantial portions of the Software. |
||||
|
> |
||||
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
> THE SOFTWARE. |
||||
|
|
||||
|
Find the source code at https://github.com/acornjs/acorn-import-meta. |
||||
|
|
||||
|
## acorn-dynamic-import |
||||
|
|
||||
|
The code in the `lib/dynamic-import` folder is licensed as MIT: |
||||
|
|
||||
|
> MIT License |
||||
|
> |
||||
|
> Copyright (c) 2016 Jordan Gensler |
||||
|
> |
||||
|
> Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
> of this software and associated documentation files (the "Software"), to deal |
||||
|
> in the Software without restriction, including without limitation the rights |
||||
|
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
> copies of the Software, and to permit persons to whom the Software is |
||||
|
> furnished to do so, subject to the following conditions: |
||||
|
> |
||||
|
> The above copyright notice and this permission notice shall be included in all |
||||
|
> copies or substantial portions of the Software. |
||||
|
> |
||||
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
> SOFTWARE. |
||||
|
|
||||
|
Find the source code at https://github.com/kesne/acorn-dynamic-import. |
@ -0,0 +1,65 @@ |
|||||
|
# acorn-node |
||||
|
|
||||
|
[Acorn](https://github.com/acornjs/acorn) preloaded with plugins for syntax parity with recent Node versions. |
||||
|
|
||||
|
It also includes versions of the plugins compiled with [Bublé](https://github.com/rich-harris/buble), so they can be run on old Node versions (0.6 and up). |
||||
|
|
||||
|
[![npm][npm-image]][npm-url] |
||||
|
[![travis][travis-image]][travis-url] |
||||
|
[![standard][standard-image]][standard-url] |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/acorn-node.svg?style=flat-square |
||||
|
[npm-url]: https://www.npmjs.com/package/acorn-node |
||||
|
[travis-image]: https://img.shields.io/travis/browserify/acorn-node/master.svg?style=flat-square |
||||
|
[travis-url]: https://travis-ci.org/browserify/acorn-node |
||||
|
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square |
||||
|
[standard-url]: http://npm.im/standard |
||||
|
|
||||
|
## Install |
||||
|
|
||||
|
``` |
||||
|
npm install acorn-node |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
```js |
||||
|
var acorn = require('acorn-node') |
||||
|
``` |
||||
|
|
||||
|
The API is the same as [acorn](https://github.com/acornjs/acorn), but the following syntax features are enabled by default: |
||||
|
|
||||
|
- Bigint syntax `10n` |
||||
|
- Numeric separators syntax `10_000` |
||||
|
- Public and private class instance fields |
||||
|
- Public and private class static fields |
||||
|
- Dynamic `import()` |
||||
|
- The `import.meta` property |
||||
|
- `export * as ns from` syntax |
||||
|
|
||||
|
And the following options have different defaults from acorn, to match Node modules: |
||||
|
|
||||
|
- `ecmaVersion: 2019` |
||||
|
- `allowHashBang: true` |
||||
|
- `allowReturnOutsideFunction: true` |
||||
|
|
||||
|
```js |
||||
|
var walk = require('acorn-node/walk') |
||||
|
``` |
||||
|
|
||||
|
The Acorn syntax tree walker. Comes preconfigured for the syntax plugins if necessary. |
||||
|
See the [acorn documentation](https://github.com/acornjs/acorn#distwalkjs) for details. |
||||
|
|
||||
|
## License |
||||
|
|
||||
|
The files in the repo root and the ./test folder are licensed as [Apache-2.0](LICENSE.md). |
||||
|
|
||||
|
The files in lib/ are generated from other packages: |
||||
|
|
||||
|
- lib/bigint: [acorn-bigint](https://github.com/acornjs/acorn-bigint]), MIT |
||||
|
- lib/class-private-elements: [acorn-class-private-elements](https://github.com/acornjs/acorn-class-private-elements), MIT |
||||
|
- lib/dynamic-import: [acorn-dynamic-import](https://github.com/acornjs/acorn-dynamic-import), MIT |
||||
|
- lib/export-ns-from: [acorn-export-ns-from](https://github.com/acornjs/acorn-export-ns-from), MIT |
||||
|
- lib/import-meta: [acorn-import-meta](https://github.com/acornjs/acorn-import-meta), MIT |
||||
|
- lib/numeric-separator: [acorn-numeric-separator](https://github.com/acornjs/acorn-numeric-separator]), MIT |
||||
|
- lib/static-class-features: [acorn-static-class-features](https://github.com/acornjs/acorn-static-class-features), MIT |
@ -0,0 +1,36 @@ |
|||||
|
var fs = require('fs') |
||||
|
var path = require('path') |
||||
|
var mkdirp = require('mkdirp') |
||||
|
var buble = require('buble') |
||||
|
|
||||
|
var HEADER = '/* Generated by `npm run build`, do not edit! */\n\n' |
||||
|
|
||||
|
function compile (name, output, fix) { |
||||
|
console.log(name, '→', output) |
||||
|
mkdirp.sync(path.dirname(path.join(__dirname, output))) |
||||
|
var source = fs.readFileSync(require.resolve(name), 'utf8') |
||||
|
if (fix) source = fix(source) |
||||
|
var result = buble.transform(source, { |
||||
|
transforms: { |
||||
|
dangerousForOf: true |
||||
|
} |
||||
|
}) |
||||
|
fs.writeFileSync(path.join(__dirname, output), HEADER + result.code, 'utf8') |
||||
|
} |
||||
|
|
||||
|
function privateClassElements (str) { |
||||
|
return str.replace('acorn-private-class-elements', '../private-class-elements') |
||||
|
} |
||||
|
|
||||
|
compile('acorn-bigint', './lib/bigint/index.js') |
||||
|
compile('acorn-numeric-separator', './lib/numeric-separator/index.js') |
||||
|
compile('acorn-dynamic-import', './lib/dynamic-import/index.js') |
||||
|
compile('acorn-import-meta', './lib/import-meta/index.js') |
||||
|
compile('acorn-export-ns-from', './lib/export-ns-from/index.js') |
||||
|
compile('acorn-class-fields', './lib/class-fields/index.js', privateClassElements) |
||||
|
compile('acorn-static-class-features', './lib/static-class-features/index.js', privateClassElements) |
||||
|
compile('acorn-private-class-elements', './lib/private-class-elements/index.js', function (str) { |
||||
|
return str.replace('class extends Parser', 'class Parser_ extends Parser') |
||||
|
// it also works with v7
|
||||
|
.replace('if (acorn.version.indexOf("6.") != 0 || acorn.version.indexOf("6.0.") == 0) {', 'if (false) {') |
||||
|
}) |
@ -0,0 +1,38 @@ |
|||||
|
var acorn = require('acorn') |
||||
|
var xtend = require('xtend') |
||||
|
|
||||
|
var CJSParser = acorn.Parser |
||||
|
.extend(require('./lib/bigint')) |
||||
|
.extend(require('./lib/class-fields')) |
||||
|
.extend(require('./lib/static-class-features')) |
||||
|
.extend(require('./lib/numeric-separator')) |
||||
|
.extend(require('./lib/dynamic-import').default) |
||||
|
var ESModulesParser = CJSParser |
||||
|
.extend(require('./lib/export-ns-from')) |
||||
|
.extend(require('./lib/import-meta')) |
||||
|
|
||||
|
function mapOptions (opts) { |
||||
|
if (!opts) opts = {} |
||||
|
return xtend({ |
||||
|
ecmaVersion: 2020, |
||||
|
allowHashBang: true, |
||||
|
allowReturnOutsideFunction: true |
||||
|
}, opts) |
||||
|
} |
||||
|
|
||||
|
function getParser (opts) { |
||||
|
if (!opts) opts = {} |
||||
|
return opts.sourceType === 'module' ? ESModulesParser : CJSParser |
||||
|
} |
||||
|
|
||||
|
module.exports = exports = xtend(acorn, { |
||||
|
parse: function parse (src, opts) { |
||||
|
return getParser(opts).parse(src, mapOptions(opts)) |
||||
|
}, |
||||
|
parseExpressionAt: function parseExpressionAt (src, offset, opts) { |
||||
|
return getParser(opts).parseExpressionAt(src, offset, mapOptions(opts)) |
||||
|
}, |
||||
|
tokenizer: function tokenizer (src, opts) { |
||||
|
return getParser(opts).tokenizer(src, mapOptions(opts)) |
||||
|
} |
||||
|
}) |
@ -0,0 +1,71 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var acorn = require("acorn") |
||||
|
var tt = acorn.tokTypes |
||||
|
var isIdentifierStart = acorn.isIdentifierStart |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
return /*@__PURE__*/(function (Parser) { |
||||
|
function anonymous () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) anonymous.__proto__ = Parser; |
||||
|
anonymous.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.parseLiteral = function parseLiteral (value) { |
||||
|
var node = Parser.prototype.parseLiteral.call(this, value) |
||||
|
if (node.raw.charCodeAt(node.raw.length - 1) == 110) { node.bigint = this.getNumberInput(node.start, node.end) } |
||||
|
return node |
||||
|
}; |
||||
|
|
||||
|
anonymous.prototype.readRadixNumber = function readRadixNumber (radix) { |
||||
|
var start = this.pos |
||||
|
this.pos += 2 // 0x
|
||||
|
var val = this.readInt(radix) |
||||
|
if (val === null) { this.raise(this.start + 2, ("Expected number in radix " + radix)) } |
||||
|
if (this.input.charCodeAt(this.pos) == 110) { |
||||
|
var str = this.getNumberInput(start, this.pos) |
||||
|
val = typeof BigInt !== "undefined" ? BigInt(str) : null |
||||
|
++this.pos |
||||
|
} else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number") } |
||||
|
return this.finishToken(tt.num, val) |
||||
|
}; |
||||
|
|
||||
|
anonymous.prototype.readNumber = function readNumber (startsWithDot) { |
||||
|
var start = this.pos |
||||
|
|
||||
|
// Not an int
|
||||
|
if (startsWithDot) { return Parser.prototype.readNumber.call(this, startsWithDot) } |
||||
|
|
||||
|
// Legacy octal
|
||||
|
if (this.input.charCodeAt(start) === 48 && this.input.charCodeAt(start + 1) !== 110) { |
||||
|
return Parser.prototype.readNumber.call(this, startsWithDot) |
||||
|
} |
||||
|
|
||||
|
if (this.readInt(10) === null) { this.raise(start, "Invalid number") } |
||||
|
|
||||
|
// Not a BigInt, reset and parse again
|
||||
|
if (this.input.charCodeAt(this.pos) != 110) { |
||||
|
this.pos = start |
||||
|
return Parser.prototype.readNumber.call(this, startsWithDot) |
||||
|
} |
||||
|
|
||||
|
var str = this.getNumberInput(start, this.pos) |
||||
|
var val = typeof BigInt !== "undefined" ? BigInt(str) : null |
||||
|
++this.pos |
||||
|
return this.finishToken(tt.num, val) |
||||
|
}; |
||||
|
|
||||
|
// This is basically a hook for acorn-numeric-separator
|
||||
|
anonymous.prototype.getNumberInput = function getNumberInput (start, end) { |
||||
|
if (Parser.prototype.getNumberInput) { return Parser.prototype.getNumberInput.call(this, start, end) } |
||||
|
return this.input.slice(start, end) |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(Parser)) |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var acorn = require("acorn") |
||||
|
var tt = acorn.tokTypes |
||||
|
var privateClassElements = require("../private-class-elements") |
||||
|
|
||||
|
function maybeParseFieldValue(field) { |
||||
|
if (this.eat(tt.eq)) { |
||||
|
var oldInFieldValue = this._inFieldValue |
||||
|
this._inFieldValue = true |
||||
|
field.value = this.parseExpression() |
||||
|
this._inFieldValue = oldInFieldValue |
||||
|
} else { field.value = null } |
||||
|
} |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
Parser = privateClassElements(Parser) |
||||
|
return /*@__PURE__*/(function (Parser) { |
||||
|
function anonymous () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) anonymous.__proto__ = Parser; |
||||
|
anonymous.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.parseClassElement = function parseClassElement (_constructorAllowsSuper) { |
||||
|
if (this.options.ecmaVersion >= 8 && (this.type == tt.name || this.type == this.privateNameToken || this.type == tt.bracketL || this.type == tt.string)) { |
||||
|
var branch = this._branch() |
||||
|
if (branch.type == tt.bracketL) { |
||||
|
var count = 0 |
||||
|
do { |
||||
|
if (branch.eat(tt.bracketL)) { ++count } |
||||
|
else if (branch.eat(tt.bracketR)) { --count } |
||||
|
else { branch.next() } |
||||
|
} while (count > 0) |
||||
|
} else { branch.next() } |
||||
|
if (branch.type == tt.eq || branch.canInsertSemicolon() || branch.type == tt.semi) { |
||||
|
var node = this.startNode() |
||||
|
if (this.type == this.privateNameToken) { |
||||
|
this.parsePrivateClassElementName(node) |
||||
|
} else { |
||||
|
this.parsePropertyName(node) |
||||
|
} |
||||
|
if ((node.key.type === "Identifier" && node.key.name === "constructor") || |
||||
|
(node.key.type === "Literal" && node.key.value === "constructor")) { |
||||
|
this.raise(node.key.start, "Classes may not have a field called constructor") |
||||
|
} |
||||
|
maybeParseFieldValue.call(this, node) |
||||
|
this.finishNode(node, "FieldDefinition") |
||||
|
this.semicolon() |
||||
|
return node |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return Parser.prototype.parseClassElement.apply(this, arguments) |
||||
|
}; |
||||
|
|
||||
|
// Prohibit arguments in class field initializers
|
||||
|
anonymous.prototype.parseIdent = function parseIdent (liberal, isBinding) { |
||||
|
var ident = Parser.prototype.parseIdent.call(this, liberal, isBinding) |
||||
|
if (this._inFieldValue && ident.name == "arguments") { this.raise(ident.start, "A class field initializer may not contain arguments") } |
||||
|
return ident |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(Parser)) |
||||
|
} |
@ -0,0 +1,86 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
'use strict'; |
||||
|
|
||||
|
Object.defineProperty(exports, "__esModule", { |
||||
|
value: true |
||||
|
}); |
||||
|
exports.DynamicImportKey = undefined; |
||||
|
|
||||
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true; } Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) { defineProperties(Constructor.prototype, protoProps); } if (staticProps) { defineProperties(Constructor, staticProps); } return Constructor; }; }(); |
||||
|
|
||||
|
var _get = function () { |
||||
|
function get(object, property, receiver) { if (object === null) { object = Function.prototype; } var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } |
||||
|
|
||||
|
return get; |
||||
|
}(); |
||||
|
|
||||
|
exports['default'] = dynamicImport; |
||||
|
|
||||
|
var _acorn = require('acorn'); |
||||
|
|
||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
||||
|
|
||||
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
||||
|
|
||||
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) { Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } } /* eslint-disable no-underscore-dangle */ |
||||
|
|
||||
|
|
||||
|
var DynamicImportKey = exports.DynamicImportKey = 'Import'; |
||||
|
|
||||
|
// NOTE: This allows `yield import()` to parse correctly.
|
||||
|
_acorn.tokTypes._import.startsExpr = true; |
||||
|
|
||||
|
function parseDynamicImport() { |
||||
|
var node = this.startNode(); |
||||
|
this.next(); |
||||
|
if (this.type !== _acorn.tokTypes.parenL) { |
||||
|
this.unexpected(); |
||||
|
} |
||||
|
return this.finishNode(node, DynamicImportKey); |
||||
|
} |
||||
|
|
||||
|
function parenAfter() { |
||||
|
return (/^(\s|\/\/.*|\/\*[^]*?\*\/)*\(/.test(this.input.slice(this.pos)) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
function dynamicImport(Parser) { |
||||
|
return function (_Parser) { |
||||
|
_inherits(_class, _Parser); |
||||
|
|
||||
|
function _class() { |
||||
|
_classCallCheck(this, _class); |
||||
|
|
||||
|
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments)); |
||||
|
} |
||||
|
|
||||
|
_createClass(_class, [{ |
||||
|
key: 'parseStatement', |
||||
|
value: function () { |
||||
|
function parseStatement(context, topLevel, exports) { |
||||
|
if (this.type === _acorn.tokTypes._import && parenAfter.call(this)) { |
||||
|
return this.parseExpressionStatement(this.startNode(), this.parseExpression()); |
||||
|
} |
||||
|
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseStatement', this).call(this, context, topLevel, exports); |
||||
|
} |
||||
|
|
||||
|
return parseStatement; |
||||
|
}() |
||||
|
}, { |
||||
|
key: 'parseExprAtom', |
||||
|
value: function () { |
||||
|
function parseExprAtom(refDestructuringErrors) { |
||||
|
if (this.type === _acorn.tokTypes._import) { |
||||
|
return parseDynamicImport.call(this); |
||||
|
} |
||||
|
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseExprAtom', this).call(this, refDestructuringErrors); |
||||
|
} |
||||
|
|
||||
|
return parseExprAtom; |
||||
|
}() |
||||
|
}]); |
||||
|
|
||||
|
return _class; |
||||
|
}(Parser); |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g |
||||
|
|
||||
|
var tt = require("acorn").tokTypes |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
return /*@__PURE__*/(function (Parser) { |
||||
|
function anonymous () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) anonymous.__proto__ = Parser; |
||||
|
anonymous.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.parseExport = function parseExport (node, exports) { |
||||
|
skipWhiteSpace.lastIndex = this.pos |
||||
|
var skip = skipWhiteSpace.exec(this.input) |
||||
|
var next = this.input.charAt(this.pos + skip[0].length) |
||||
|
if (next !== "*") { return Parser.prototype.parseExport.call(this, node, exports) } |
||||
|
|
||||
|
this.next() |
||||
|
var specifier = this.startNode() |
||||
|
this.expect(tt.star) |
||||
|
if (this.eatContextual("as")) { |
||||
|
node.declaration = null |
||||
|
specifier.exported = this.parseIdent(true) |
||||
|
this.checkExport(exports, specifier.exported.name, this.lastTokStart) |
||||
|
node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")] |
||||
|
} |
||||
|
this.expectContextual("from") |
||||
|
if (this.type !== tt.string) { this.unexpected() } |
||||
|
node.source = this.parseExprAtom() |
||||
|
this.semicolon() |
||||
|
return this.finishNode(node, node.specifiers ? "ExportNamedDeclaration" : "ExportAllDeclaration") |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(Parser)) |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var tt = require("acorn").tokTypes |
||||
|
|
||||
|
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g |
||||
|
|
||||
|
var nextTokenIsDot = function (parser) { |
||||
|
skipWhiteSpace.lastIndex = parser.pos |
||||
|
var skip = skipWhiteSpace.exec(parser.input) |
||||
|
var next = parser.pos + skip[0].length |
||||
|
return parser.input.slice(next, next + 1) === "." |
||||
|
} |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
return /*@__PURE__*/(function (Parser) { |
||||
|
function anonymous () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) anonymous.__proto__ = Parser; |
||||
|
anonymous.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.parseExprAtom = function parseExprAtom (refDestructuringErrors) { |
||||
|
if (this.type !== tt._import || !nextTokenIsDot(this)) { return Parser.prototype.parseExprAtom.call(this, refDestructuringErrors) } |
||||
|
|
||||
|
if (!this.options.allowImportExportEverywhere && !this.inModule) { |
||||
|
this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'") |
||||
|
} |
||||
|
|
||||
|
var node = this.startNode() |
||||
|
node.meta = this.parseIdent(true) |
||||
|
this.expect(tt.dot) |
||||
|
node.property = this.parseIdent(true) |
||||
|
if (node.property.name !== "meta") { |
||||
|
this.raiseRecoverable(node.property.start, "The only valid meta property for import is import.meta") |
||||
|
} |
||||
|
return this.finishNode(node, "MetaProperty") |
||||
|
}; |
||||
|
|
||||
|
anonymous.prototype.parseStatement = function parseStatement (context, topLevel, exports) { |
||||
|
if (this.type !== tt._import || !nextTokenIsDot(this)) { |
||||
|
return Parser.prototype.parseStatement.call(this, context, topLevel, exports) |
||||
|
} |
||||
|
|
||||
|
var node = this.startNode() |
||||
|
var expr = this.parseExpression() |
||||
|
return this.parseExpressionStatement(node, expr) |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(Parser)) |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
return /*@__PURE__*/(function (Parser) { |
||||
|
function anonymous () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) anonymous.__proto__ = Parser; |
||||
|
anonymous.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.readInt = function readInt (radix, len) { |
||||
|
// Hack: len is only != null for unicode escape sequences,
|
||||
|
// where numeric separators are not allowed
|
||||
|
if (len != null) { return Parser.prototype.readInt.call(this, radix, len) } |
||||
|
|
||||
|
var start = this.pos, total = 0, acceptUnderscore = false |
||||
|
for (;;) { |
||||
|
var code = this.input.charCodeAt(this.pos), val = (void 0) |
||||
|
if (code >= 97) { val = code - 97 + 10 } // a
|
||||
|
else if (code == 95) { |
||||
|
if (!acceptUnderscore) { this.raise(this.pos, "Invalid numeric separator") } |
||||
|
++this.pos |
||||
|
acceptUnderscore = false |
||||
|
continue |
||||
|
} else if (code >= 65) { val = code - 65 + 10 } // A
|
||||
|
else if (code >= 48 && code <= 57) { val = code - 48 } // 0-9
|
||||
|
else { val = Infinity } |
||||
|
if (val >= radix) { break } |
||||
|
++this.pos |
||||
|
total = total * radix + val |
||||
|
acceptUnderscore = true |
||||
|
} |
||||
|
if (this.pos === start) { return null } |
||||
|
if (!acceptUnderscore) { this.raise(this.pos - 1, "Invalid numeric separator") } |
||||
|
|
||||
|
return total |
||||
|
}; |
||||
|
|
||||
|
anonymous.prototype.readNumber = function readNumber (startsWithDot) { |
||||
|
var token = Parser.prototype.readNumber.call(this, startsWithDot) |
||||
|
var octal = this.end - this.start >= 2 && this.input.charCodeAt(this.start) === 48 |
||||
|
var stripped = this.getNumberInput(this.start, this.end) |
||||
|
if (stripped.length < this.end - this.start) { |
||||
|
if (octal) { this.raise(this.start, "Invalid number") } |
||||
|
this.value = parseFloat(stripped) |
||||
|
} |
||||
|
return token |
||||
|
}; |
||||
|
|
||||
|
// This is used by acorn-bigint
|
||||
|
anonymous.prototype.getNumberInput = function getNumberInput (start, end) { |
||||
|
return this.input.slice(start, end).replace(/_/g, "") |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(Parser)) |
||||
|
} |
@ -0,0 +1,135 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var acorn = require("acorn") |
||||
|
if (false) { |
||||
|
throw new Error(("acorn-private-class-elements requires acorn@^6.1.0, not " + (acorn.version))) |
||||
|
} |
||||
|
var tt = acorn.tokTypes |
||||
|
var TokenType = acorn.TokenType |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
// Only load this plugin once.
|
||||
|
if (Parser.prototype.parsePrivateName) { |
||||
|
return Parser |
||||
|
} |
||||
|
|
||||
|
// Make sure `Parser` comes from the same acorn as our `tt`,
|
||||
|
// otherwise the comparisons fail.
|
||||
|
var cur = Parser |
||||
|
while (cur && cur !== acorn.Parser) { |
||||
|
cur = cur.__proto__ |
||||
|
} |
||||
|
if (cur !== acorn.Parser) { |
||||
|
throw new Error("acorn-private-class-elements does not support mixing different acorn copies") |
||||
|
} |
||||
|
|
||||
|
Parser = /*@__PURE__*/(function (Parser) { |
||||
|
function Parser_ () { |
||||
|
Parser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( Parser ) Parser_.__proto__ = Parser; |
||||
|
Parser_.prototype = Object.create( Parser && Parser.prototype ); |
||||
|
Parser_.prototype.constructor = Parser_; |
||||
|
|
||||
|
Parser_.prototype._branch = function _branch () { |
||||
|
this.__branch = this.__branch || new Parser({ecmaVersion: this.options.ecmaVersion}, this.input) |
||||
|
this.__branch.end = this.end |
||||
|
this.__branch.pos = this.pos |
||||
|
this.__branch.type = this.type |
||||
|
this.__branch.value = this.value |
||||
|
this.__branch.containsEsc = this.containsEsc |
||||
|
return this.__branch |
||||
|
}; |
||||
|
|
||||
|
Parser_.prototype.parsePrivateClassElementName = function parsePrivateClassElementName (element) { |
||||
|
element.computed = false |
||||
|
element.key = this.parsePrivateName() |
||||
|
if (element.key.name == "constructor") { this.raise(element.key.start, "Classes may not have a private element named constructor") } |
||||
|
var accept = {get: "set", set: "get"}[element.kind] |
||||
|
var privateBoundNames = this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1] |
||||
|
if (Object.prototype.hasOwnProperty.call(privateBoundNames, element.key.name) && privateBoundNames[element.key.name] !== accept) { |
||||
|
this.raise(element.start, "Duplicate private element") |
||||
|
} |
||||
|
privateBoundNames[element.key.name] = element.kind || true |
||||
|
delete this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][element.key.name] |
||||
|
return element.key |
||||
|
}; |
||||
|
|
||||
|
Parser_.prototype.parsePrivateName = function parsePrivateName () { |
||||
|
var node = this.startNode() |
||||
|
node.name = this.value |
||||
|
this.next() |
||||
|
this.finishNode(node, "PrivateName") |
||||
|
if (this.options.allowReserved == "never") { this.checkUnreserved(node) } |
||||
|
return node |
||||
|
}; |
||||
|
|
||||
|
// Parse # token
|
||||
|
Parser_.prototype.getTokenFromCode = function getTokenFromCode (code) { |
||||
|
if (code === 35) { |
||||
|
++this.pos |
||||
|
var word = this.readWord1() |
||||
|
return this.finishToken(this.privateNameToken, word) |
||||
|
} |
||||
|
return Parser.prototype.getTokenFromCode.call(this, code) |
||||
|
}; |
||||
|
|
||||
|
// Manage stacks and check for undeclared private names
|
||||
|
Parser_.prototype.parseClass = function parseClass (node, isStatement) { |
||||
|
this._privateBoundNamesStack = this._privateBoundNamesStack || [] |
||||
|
var privateBoundNames = Object.create(this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1] || null) |
||||
|
this._privateBoundNamesStack.push(privateBoundNames) |
||||
|
this._unresolvedPrivateNamesStack = this._unresolvedPrivateNamesStack || [] |
||||
|
var unresolvedPrivateNames = Object.create(null) |
||||
|
this._unresolvedPrivateNamesStack.push(unresolvedPrivateNames) |
||||
|
var _return = Parser.prototype.parseClass.call(this, node, isStatement) |
||||
|
this._privateBoundNamesStack.pop() |
||||
|
this._unresolvedPrivateNamesStack.pop() |
||||
|
if (!this._unresolvedPrivateNamesStack.length) { |
||||
|
var names = Object.keys(unresolvedPrivateNames) |
||||
|
if (names.length) { |
||||
|
names.sort(function (n1, n2) { return unresolvedPrivateNames[n1] - unresolvedPrivateNames[n2]; }) |
||||
|
this.raise(unresolvedPrivateNames[names[0]], "Usage of undeclared private name") |
||||
|
} |
||||
|
} else { Object.assign(this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1], unresolvedPrivateNames) } |
||||
|
return _return |
||||
|
}; |
||||
|
|
||||
|
// Parse private element access
|
||||
|
Parser_.prototype.parseSubscript = function parseSubscript (base, startPos, startLoc, noCalls, maybeAsyncArrow) { |
||||
|
if (!this.eat(tt.dot)) { |
||||
|
return Parser.prototype.parseSubscript.call(this, base, startPos, startLoc, noCalls, maybeAsyncArrow) |
||||
|
} |
||||
|
var node = this.startNodeAt(startPos, startLoc) |
||||
|
node.object = base |
||||
|
node.computed = false |
||||
|
if (this.type == this.privateNameToken) { |
||||
|
node.property = this.parsePrivateName() |
||||
|
if (!this._privateBoundNamesStack.length || !this._privateBoundNamesStack[this._privateBoundNamesStack.length - 1][node.property.name]) { |
||||
|
this._unresolvedPrivateNamesStack[this._unresolvedPrivateNamesStack.length - 1][node.property.name] = node.property.start |
||||
|
} |
||||
|
} else { |
||||
|
node.property = this.parseIdent(true) |
||||
|
} |
||||
|
return this.finishNode(node, "MemberExpression") |
||||
|
}; |
||||
|
|
||||
|
// Prohibit delete of private class elements
|
||||
|
Parser_.prototype.parseMaybeUnary = function parseMaybeUnary (refDestructuringErrors, sawUnary) { |
||||
|
var _return = Parser.prototype.parseMaybeUnary.call(this, refDestructuringErrors, sawUnary) |
||||
|
if (_return.operator == "delete") { |
||||
|
if (_return.argument.type == "MemberExpression" && _return.argument.property.type == "PrivateName") { |
||||
|
this.raise(_return.start, "Private elements may not be deleted") |
||||
|
} |
||||
|
} |
||||
|
return _return |
||||
|
}; |
||||
|
|
||||
|
return Parser_; |
||||
|
}(Parser)) |
||||
|
Parser.prototype.privateNameToken = new TokenType("privateName") |
||||
|
return Parser |
||||
|
} |
@ -0,0 +1,139 @@ |
|||||
|
/* Generated by `npm run build`, do not edit! */ |
||||
|
|
||||
|
"use strict" |
||||
|
|
||||
|
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g |
||||
|
|
||||
|
var acorn = require("acorn") |
||||
|
var tt = acorn.tokTypes |
||||
|
|
||||
|
function maybeParseFieldValue(field) { |
||||
|
if (this.eat(tt.eq)) { |
||||
|
var oldInFieldValue = this._inStaticFieldValue |
||||
|
this._inStaticFieldValue = true |
||||
|
field.value = this.parseExpression() |
||||
|
this._inStaticFieldValue = oldInFieldValue |
||||
|
} else { field.value = null } |
||||
|
} |
||||
|
|
||||
|
var privateClassElements = require("../private-class-elements") |
||||
|
|
||||
|
module.exports = function(Parser) { |
||||
|
var ExtendedParser = privateClassElements(Parser) |
||||
|
|
||||
|
return /*@__PURE__*/(function (ExtendedParser) { |
||||
|
function anonymous () { |
||||
|
ExtendedParser.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
if ( ExtendedParser ) anonymous.__proto__ = ExtendedParser; |
||||
|
anonymous.prototype = Object.create( ExtendedParser && ExtendedParser.prototype ); |
||||
|
anonymous.prototype.constructor = anonymous; |
||||
|
|
||||
|
anonymous.prototype.parseClassElement = function parseClassElement (_constructorAllowsSuper) { |
||||
|
var this$1 = this; |
||||
|
|
||||
|
if (this.eat(tt.semi)) { return null } |
||||
|
|
||||
|
var node = this.startNode() |
||||
|
|
||||
|
var tryContextual = function (k, noLineBreak) { |
||||
|
if (typeof noLineBreak == "undefined") { noLineBreak = false } |
||||
|
var start = this$1.start, startLoc = this$1.startLoc |
||||
|
if (!this$1.eatContextual(k)) { return false } |
||||
|
if (this$1.type !== tt.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true } |
||||
|
if (node.key) { this$1.unexpected() } |
||||
|
node.computed = false |
||||
|
node.key = this$1.startNodeAt(start, startLoc) |
||||
|
node.key.name = k |
||||
|
this$1.finishNode(node.key, "Identifier") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
node.static = tryContextual("static") |
||||
|
if (!node.static) { return ExtendedParser.prototype.parseClassElement.apply(this, arguments) } |
||||
|
|
||||
|
var isGenerator = this.eat(tt.star) |
||||
|
var isAsync = false |
||||
|
if (!isGenerator) { |
||||
|
// Special-case for `async`, since `parseClassMember` currently looks
|
||||
|
// for `(` to determine whether `async` is a method name
|
||||
|
if (this.options.ecmaVersion >= 8 && this.isContextual("async")) { |
||||
|
skipWhiteSpace.lastIndex = this.pos |
||||
|
var skip = skipWhiteSpace.exec(this.input) |
||||
|
var next = this.input.charAt(this.pos + skip[0].length) |
||||
|
if (next === ";" || next === "=") { |
||||
|
node.key = this.parseIdent(true) |
||||
|
node.computed = false |
||||
|
maybeParseFieldValue.call(this, node) |
||||
|
this.finishNode(node, "FieldDefinition") |
||||
|
this.semicolon() |
||||
|
return node |
||||
|
} else if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) { |
||||
|
isAsync = true |
||||
|
isGenerator = this.options.ecmaVersion >= 9 && this.eat(tt.star) |
||||
|
} |
||||
|
} else if (tryContextual("get")) { |
||||
|
node.kind = "get" |
||||
|
} else if (tryContextual("set")) { |
||||
|
node.kind = "set" |
||||
|
} |
||||
|
} |
||||
|
if (this.type === this.privateNameToken) { |
||||
|
this.parsePrivateClassElementName(node) |
||||
|
if (this.type !== tt.parenL) { |
||||
|
if (node.key.name === "prototype") { |
||||
|
this.raise(node.key.start, "Classes may not have a private static property named prototype") |
||||
|
} |
||||
|
maybeParseFieldValue.call(this, node) |
||||
|
this.finishNode(node, "FieldDefinition") |
||||
|
this.semicolon() |
||||
|
return node |
||||
|
} |
||||
|
} else if (!node.key) { |
||||
|
this.parsePropertyName(node) |
||||
|
if ((node.key.name || node.key.value) === "prototype" && !node.computed) { |
||||
|
this.raise(node.key.start, "Classes may not have a static property named prototype") |
||||
|
} |
||||
|
} |
||||
|
if (!node.kind) { node.kind = "method" } |
||||
|
this.parseClassMethod(node, isGenerator, isAsync) |
||||
|
if (!node.kind && (node.key.name || node.key.value) === "constructor" && !node.computed) { |
||||
|
this.raise(node.key.start, "Classes may not have a static field named constructor") |
||||
|
} |
||||
|
if (node.kind === "get" && node.value.params.length !== 0) { |
||||
|
this.raiseRecoverable(node.value.start, "getter should have no params") |
||||
|
} |
||||
|
if (node.kind === "set" && node.value.params.length !== 1) { |
||||
|
this.raiseRecoverable(node.value.start, "setter should have exactly one param") |
||||
|
} |
||||
|
if (node.kind === "set" && node.value.params[0].type === "RestElement") { |
||||
|
this.raiseRecoverable(node.value.params[0].start, "Setter cannot use rest params") |
||||
|
} |
||||
|
|
||||
|
return node |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
// Parse public static fields
|
||||
|
anonymous.prototype.parseClassMethod = function parseClassMethod (method, isGenerator, isAsync, _allowsDirectSuper) { |
||||
|
if (isGenerator || isAsync || method.kind != "method" || !method.static || this.options.ecmaVersion < 8 || this.type == tt.parenL) { |
||||
|
return ExtendedParser.prototype.parseClassMethod.apply(this, arguments) |
||||
|
} |
||||
|
maybeParseFieldValue.call(this, method) |
||||
|
delete method.kind |
||||
|
method = this.finishNode(method, "FieldDefinition") |
||||
|
this.semicolon() |
||||
|
return method |
||||
|
}; |
||||
|
|
||||
|
// Prohibit arguments in class field initializers
|
||||
|
anonymous.prototype.parseIdent = function parseIdent (liberal, isBinding) { |
||||
|
var ident = ExtendedParser.prototype.parseIdent.call(this, liberal, isBinding) |
||||
|
if (this._inStaticFieldValue && ident.name == "arguments") { this.raise(ident.start, "A static class field initializer may not contain arguments") } |
||||
|
return ident |
||||
|
}; |
||||
|
|
||||
|
return anonymous; |
||||
|
}(ExtendedParser)) |
||||
|
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue