protobufjs 6.11.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/README.md +7 -174
  2. package/dist/light/protobuf.js +77 -29
  3. package/dist/light/protobuf.js.map +1 -1
  4. package/dist/light/protobuf.min.js +3 -3
  5. package/dist/light/protobuf.min.js.map +1 -1
  6. package/dist/minimal/protobuf.js +27 -10
  7. package/dist/minimal/protobuf.js.map +1 -1
  8. package/dist/minimal/protobuf.min.js +3 -3
  9. package/dist/minimal/protobuf.min.js.map +1 -1
  10. package/dist/protobuf.js +163 -61
  11. package/dist/protobuf.js.map +1 -1
  12. package/dist/protobuf.min.js +3 -3
  13. package/dist/protobuf.min.js.map +1 -1
  14. package/index.d.ts +9 -7
  15. package/package.json +14 -33
  16. package/scripts/postinstall.js +0 -3
  17. package/src/converter.js +10 -4
  18. package/src/decoder.js +4 -3
  19. package/src/enum.js +24 -7
  20. package/src/field.js +6 -3
  21. package/src/namespace.js +3 -3
  22. package/src/parse.js +55 -16
  23. package/src/roots.js +1 -1
  24. package/src/tokenize.js +31 -16
  25. package/src/util/minimal.js +24 -7
  26. package/src/util.js +3 -0
  27. package/src/wrappers.js +2 -2
  28. package/tsconfig.json +2 -1
  29. package/CHANGELOG.md +0 -1019
  30. package/bin/pbjs +0 -6
  31. package/bin/pbts +0 -6
  32. package/cli/LICENSE +0 -33
  33. package/cli/README.md +0 -174
  34. package/cli/bin/pbjs +0 -6
  35. package/cli/bin/pbts +0 -6
  36. package/cli/index.d.ts +0 -3
  37. package/cli/index.js +0 -3
  38. package/cli/lib/tsd-jsdoc/LICENSE +0 -21
  39. package/cli/lib/tsd-jsdoc/README.md +0 -23
  40. package/cli/lib/tsd-jsdoc/plugin.js +0 -21
  41. package/cli/lib/tsd-jsdoc/publish.js +0 -705
  42. package/cli/lib/tsd-jsdoc.json +0 -18
  43. package/cli/node_modules/.package-lock.json +0 -256
  44. package/cli/node_modules/acorn/CHANGELOG.md +0 -620
  45. package/cli/node_modules/acorn/LICENSE +0 -21
  46. package/cli/node_modules/acorn/README.md +0 -269
  47. package/cli/node_modules/acorn/bin/acorn +0 -4
  48. package/cli/node_modules/acorn/dist/acorn.d.ts +0 -209
  49. package/cli/node_modules/acorn/dist/acorn.js +0 -5186
  50. package/cli/node_modules/acorn/dist/acorn.js.map +0 -1
  51. package/cli/node_modules/acorn/dist/acorn.mjs +0 -5155
  52. package/cli/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
  53. package/cli/node_modules/acorn/dist/acorn.mjs.map +0 -1
  54. package/cli/node_modules/acorn/dist/bin.js +0 -64
  55. package/cli/node_modules/acorn/package.json +0 -35
  56. package/cli/node_modules/acorn-jsx/LICENSE +0 -19
  57. package/cli/node_modules/acorn-jsx/README.md +0 -40
  58. package/cli/node_modules/acorn-jsx/index.js +0 -488
  59. package/cli/node_modules/acorn-jsx/package.json +0 -27
  60. package/cli/node_modules/acorn-jsx/xhtml.js +0 -255
  61. package/cli/node_modules/balanced-match/.npmignore +0 -5
  62. package/cli/node_modules/balanced-match/LICENSE.md +0 -21
  63. package/cli/node_modules/balanced-match/README.md +0 -91
  64. package/cli/node_modules/balanced-match/index.js +0 -59
  65. package/cli/node_modules/balanced-match/package.json +0 -49
  66. package/cli/node_modules/brace-expansion/LICENSE +0 -21
  67. package/cli/node_modules/brace-expansion/README.md +0 -129
  68. package/cli/node_modules/brace-expansion/index.js +0 -201
  69. package/cli/node_modules/brace-expansion/package.json +0 -47
  70. package/cli/node_modules/concat-map/.travis.yml +0 -4
  71. package/cli/node_modules/concat-map/LICENSE +0 -18
  72. package/cli/node_modules/concat-map/README.markdown +0 -62
  73. package/cli/node_modules/concat-map/example/map.js +0 -6
  74. package/cli/node_modules/concat-map/index.js +0 -13
  75. package/cli/node_modules/concat-map/package.json +0 -43
  76. package/cli/node_modules/concat-map/test/map.js +0 -39
  77. package/cli/node_modules/deep-is/.npmignore +0 -1
  78. package/cli/node_modules/deep-is/.travis.yml +0 -6
  79. package/cli/node_modules/deep-is/LICENSE +0 -22
  80. package/cli/node_modules/deep-is/README.markdown +0 -70
  81. package/cli/node_modules/deep-is/example/cmp.js +0 -11
  82. package/cli/node_modules/deep-is/index.js +0 -102
  83. package/cli/node_modules/deep-is/package.json +0 -61
  84. package/cli/node_modules/deep-is/test/NaN.js +0 -16
  85. package/cli/node_modules/deep-is/test/cmp.js +0 -23
  86. package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +0 -15
  87. package/cli/node_modules/escodegen/LICENSE.BSD +0 -21
  88. package/cli/node_modules/escodegen/README.md +0 -84
  89. package/cli/node_modules/escodegen/bin/escodegen.js +0 -77
  90. package/cli/node_modules/escodegen/bin/esgenerate.js +0 -64
  91. package/cli/node_modules/escodegen/escodegen.js +0 -2647
  92. package/cli/node_modules/escodegen/package.json +0 -62
  93. package/cli/node_modules/eslint-visitor-keys/CHANGELOG.md +0 -25
  94. package/cli/node_modules/eslint-visitor-keys/LICENSE +0 -201
  95. package/cli/node_modules/eslint-visitor-keys/README.md +0 -98
  96. package/cli/node_modules/eslint-visitor-keys/lib/index.js +0 -81
  97. package/cli/node_modules/eslint-visitor-keys/lib/visitor-keys.json +0 -284
  98. package/cli/node_modules/eslint-visitor-keys/package.json +0 -40
  99. package/cli/node_modules/espree/CHANGELOG.md +0 -509
  100. package/cli/node_modules/espree/LICENSE +0 -25
  101. package/cli/node_modules/espree/README.md +0 -233
  102. package/cli/node_modules/espree/espree.js +0 -177
  103. package/cli/node_modules/espree/lib/ast-node-types.js +0 -96
  104. package/cli/node_modules/espree/lib/espree.js +0 -286
  105. package/cli/node_modules/espree/lib/features.js +0 -29
  106. package/cli/node_modules/espree/lib/options.js +0 -106
  107. package/cli/node_modules/espree/lib/token-translator.js +0 -263
  108. package/cli/node_modules/espree/lib/visitor-keys.js +0 -123
  109. package/cli/node_modules/espree/package.json +0 -64
  110. package/cli/node_modules/esprima/ChangeLog +0 -235
  111. package/cli/node_modules/esprima/LICENSE.BSD +0 -21
  112. package/cli/node_modules/esprima/README.md +0 -46
  113. package/cli/node_modules/esprima/bin/esparse.js +0 -139
  114. package/cli/node_modules/esprima/bin/esvalidate.js +0 -236
  115. package/cli/node_modules/esprima/dist/esprima.js +0 -6709
  116. package/cli/node_modules/esprima/package.json +0 -112
  117. package/cli/node_modules/estraverse/.jshintrc +0 -16
  118. package/cli/node_modules/estraverse/LICENSE.BSD +0 -19
  119. package/cli/node_modules/estraverse/README.md +0 -153
  120. package/cli/node_modules/estraverse/estraverse.js +0 -801
  121. package/cli/node_modules/estraverse/gulpfile.js +0 -70
  122. package/cli/node_modules/estraverse/package.json +0 -40
  123. package/cli/node_modules/esutils/LICENSE.BSD +0 -19
  124. package/cli/node_modules/esutils/README.md +0 -174
  125. package/cli/node_modules/esutils/lib/ast.js +0 -144
  126. package/cli/node_modules/esutils/lib/code.js +0 -135
  127. package/cli/node_modules/esutils/lib/keyword.js +0 -165
  128. package/cli/node_modules/esutils/lib/utils.js +0 -33
  129. package/cli/node_modules/esutils/package.json +0 -44
  130. package/cli/node_modules/fast-levenshtein/LICENSE.md +0 -25
  131. package/cli/node_modules/fast-levenshtein/README.md +0 -104
  132. package/cli/node_modules/fast-levenshtein/levenshtein.js +0 -136
  133. package/cli/node_modules/fast-levenshtein/package.json +0 -39
  134. package/cli/node_modules/fs.realpath/LICENSE +0 -43
  135. package/cli/node_modules/fs.realpath/README.md +0 -33
  136. package/cli/node_modules/fs.realpath/index.js +0 -66
  137. package/cli/node_modules/fs.realpath/old.js +0 -303
  138. package/cli/node_modules/fs.realpath/package.json +0 -26
  139. package/cli/node_modules/glob/LICENSE +0 -21
  140. package/cli/node_modules/glob/README.md +0 -375
  141. package/cli/node_modules/glob/changelog.md +0 -67
  142. package/cli/node_modules/glob/common.js +0 -240
  143. package/cli/node_modules/glob/glob.js +0 -790
  144. package/cli/node_modules/glob/package.json +0 -46
  145. package/cli/node_modules/glob/sync.js +0 -486
  146. package/cli/node_modules/inflight/LICENSE +0 -15
  147. package/cli/node_modules/inflight/README.md +0 -37
  148. package/cli/node_modules/inflight/inflight.js +0 -54
  149. package/cli/node_modules/inflight/package.json +0 -29
  150. package/cli/node_modules/inherits/LICENSE +0 -16
  151. package/cli/node_modules/inherits/README.md +0 -42
  152. package/cli/node_modules/inherits/inherits.js +0 -9
  153. package/cli/node_modules/inherits/inherits_browser.js +0 -27
  154. package/cli/node_modules/inherits/package.json +0 -29
  155. package/cli/node_modules/levn/LICENSE +0 -22
  156. package/cli/node_modules/levn/README.md +0 -196
  157. package/cli/node_modules/levn/lib/cast.js +0 -298
  158. package/cli/node_modules/levn/lib/coerce.js +0 -285
  159. package/cli/node_modules/levn/lib/index.js +0 -22
  160. package/cli/node_modules/levn/lib/parse-string.js +0 -113
  161. package/cli/node_modules/levn/lib/parse.js +0 -102
  162. package/cli/node_modules/levn/package.json +0 -47
  163. package/cli/node_modules/minimatch/LICENSE +0 -15
  164. package/cli/node_modules/minimatch/README.md +0 -209
  165. package/cli/node_modules/minimatch/minimatch.js +0 -923
  166. package/cli/node_modules/minimatch/package.json +0 -30
  167. package/cli/node_modules/once/LICENSE +0 -15
  168. package/cli/node_modules/once/README.md +0 -79
  169. package/cli/node_modules/once/once.js +0 -42
  170. package/cli/node_modules/once/package.json +0 -33
  171. package/cli/node_modules/optionator/CHANGELOG.md +0 -56
  172. package/cli/node_modules/optionator/LICENSE +0 -22
  173. package/cli/node_modules/optionator/README.md +0 -238
  174. package/cli/node_modules/optionator/lib/help.js +0 -260
  175. package/cli/node_modules/optionator/lib/index.js +0 -465
  176. package/cli/node_modules/optionator/lib/util.js +0 -54
  177. package/cli/node_modules/optionator/package.json +0 -44
  178. package/cli/node_modules/path-is-absolute/index.js +0 -20
  179. package/cli/node_modules/path-is-absolute/license +0 -21
  180. package/cli/node_modules/path-is-absolute/package.json +0 -43
  181. package/cli/node_modules/path-is-absolute/readme.md +0 -59
  182. package/cli/node_modules/prelude-ls/CHANGELOG.md +0 -99
  183. package/cli/node_modules/prelude-ls/LICENSE +0 -22
  184. package/cli/node_modules/prelude-ls/README.md +0 -15
  185. package/cli/node_modules/prelude-ls/lib/Func.js +0 -65
  186. package/cli/node_modules/prelude-ls/lib/List.js +0 -686
  187. package/cli/node_modules/prelude-ls/lib/Num.js +0 -130
  188. package/cli/node_modules/prelude-ls/lib/Obj.js +0 -154
  189. package/cli/node_modules/prelude-ls/lib/Str.js +0 -92
  190. package/cli/node_modules/prelude-ls/lib/index.js +0 -178
  191. package/cli/node_modules/prelude-ls/package.json +0 -52
  192. package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
  193. package/cli/node_modules/rimraf/LICENSE +0 -15
  194. package/cli/node_modules/rimraf/README.md +0 -101
  195. package/cli/node_modules/rimraf/bin.js +0 -68
  196. package/cli/node_modules/rimraf/package.json +0 -32
  197. package/cli/node_modules/rimraf/rimraf.js +0 -360
  198. package/cli/node_modules/source-map/CHANGELOG.md +0 -301
  199. package/cli/node_modules/source-map/LICENSE +0 -28
  200. package/cli/node_modules/source-map/README.md +0 -742
  201. package/cli/node_modules/source-map/dist/source-map.debug.js +0 -3234
  202. package/cli/node_modules/source-map/dist/source-map.js +0 -3233
  203. package/cli/node_modules/source-map/dist/source-map.min.js +0 -2
  204. package/cli/node_modules/source-map/dist/source-map.min.js.map +0 -1
  205. package/cli/node_modules/source-map/lib/array-set.js +0 -121
  206. package/cli/node_modules/source-map/lib/base64-vlq.js +0 -140
  207. package/cli/node_modules/source-map/lib/base64.js +0 -67
  208. package/cli/node_modules/source-map/lib/binary-search.js +0 -111
  209. package/cli/node_modules/source-map/lib/mapping-list.js +0 -79
  210. package/cli/node_modules/source-map/lib/quick-sort.js +0 -114
  211. package/cli/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  212. package/cli/node_modules/source-map/lib/source-map-generator.js +0 -425
  213. package/cli/node_modules/source-map/lib/source-node.js +0 -413
  214. package/cli/node_modules/source-map/lib/util.js +0 -488
  215. package/cli/node_modules/source-map/package.json +0 -73
  216. package/cli/node_modules/source-map/source-map.d.ts +0 -98
  217. package/cli/node_modules/source-map/source-map.js +0 -8
  218. package/cli/node_modules/tmp/CHANGELOG.md +0 -288
  219. package/cli/node_modules/tmp/LICENSE +0 -21
  220. package/cli/node_modules/tmp/README.md +0 -365
  221. package/cli/node_modules/tmp/lib/tmp.js +0 -780
  222. package/cli/node_modules/tmp/package.json +0 -58
  223. package/cli/node_modules/type-check/LICENSE +0 -22
  224. package/cli/node_modules/type-check/README.md +0 -210
  225. package/cli/node_modules/type-check/lib/check.js +0 -126
  226. package/cli/node_modules/type-check/lib/index.js +0 -16
  227. package/cli/node_modules/type-check/lib/parse-type.js +0 -196
  228. package/cli/node_modules/type-check/package.json +0 -40
  229. package/cli/node_modules/word-wrap/LICENSE +0 -21
  230. package/cli/node_modules/word-wrap/README.md +0 -182
  231. package/cli/node_modules/word-wrap/index.d.ts +0 -50
  232. package/cli/node_modules/word-wrap/index.js +0 -46
  233. package/cli/node_modules/word-wrap/package.json +0 -77
  234. package/cli/node_modules/wrappy/LICENSE +0 -15
  235. package/cli/node_modules/wrappy/README.md +0 -36
  236. package/cli/node_modules/wrappy/package.json +0 -29
  237. package/cli/node_modules/wrappy/wrappy.js +0 -33
  238. package/cli/package.json +0 -8
  239. package/cli/package.standalone.json +0 -32
  240. package/cli/pbjs.d.ts +0 -9
  241. package/cli/pbjs.js +0 -330
  242. package/cli/pbts.d.ts +0 -9
  243. package/cli/pbts.js +0 -197
  244. package/cli/targets/json-module.js +0 -38
  245. package/cli/targets/json.js +0 -8
  246. package/cli/targets/proto.js +0 -326
  247. package/cli/targets/proto2.js +0 -10
  248. package/cli/targets/proto3.js +0 -10
  249. package/cli/targets/static-module.js +0 -29
  250. package/cli/targets/static.js +0 -711
  251. package/cli/util.js +0 -183
  252. package/cli/wrappers/amd.js +0 -7
  253. package/cli/wrappers/closure.js +0 -7
  254. package/cli/wrappers/commonjs.js +0 -7
  255. package/cli/wrappers/default.js +0 -15
  256. package/cli/wrappers/es6.js +0 -5
  257. package/dist/README.md +0 -31
  258. package/dist/light/README.md +0 -31
  259. package/dist/minimal/README.md +0 -31
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var fs = require('fs');
5
- var acorn = require('./acorn.js');
6
-
7
- var infile, forceFile, silent = false, compact = false, tokenize = false;
8
- var options = {};
9
-
10
- function help(status) {
11
- var print = (status === 0) ? console.log : console.error;
12
- print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]");
13
- print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]");
14
- process.exit(status);
15
- }
16
-
17
- for (var i = 2; i < process.argv.length; ++i) {
18
- var arg = process.argv[i];
19
- if ((arg === "-" || arg[0] !== "-") && !infile) { infile = arg; }
20
- else if (arg === "--" && !infile && i + 2 === process.argv.length) { forceFile = infile = process.argv[++i]; }
21
- else if (arg === "--locations") { options.locations = true; }
22
- else if (arg === "--allow-hash-bang") { options.allowHashBang = true; }
23
- else if (arg === "--silent") { silent = true; }
24
- else if (arg === "--compact") { compact = true; }
25
- else if (arg === "--help") { help(0); }
26
- else if (arg === "--tokenize") { tokenize = true; }
27
- else if (arg === "--module") { options.sourceType = "module"; }
28
- else {
29
- var match = arg.match(/^--ecma(\d+)$/);
30
- if (match)
31
- { options.ecmaVersion = +match[1]; }
32
- else
33
- { help(1); }
34
- }
35
- }
36
-
37
- function run(code) {
38
- var result;
39
- try {
40
- if (!tokenize) {
41
- result = acorn.parse(code, options);
42
- } else {
43
- result = [];
44
- var tokenizer = acorn.tokenizer(code, options), token;
45
- do {
46
- token = tokenizer.getToken();
47
- result.push(token);
48
- } while (token.type !== acorn.tokTypes.eof)
49
- }
50
- } catch (e) {
51
- console.error(infile && infile !== "-" ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + infile + " " + m.slice(1); }) : e.message);
52
- process.exit(1);
53
- }
54
- if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); }
55
- }
56
-
57
- if (forceFile || infile && infile !== "-") {
58
- run(fs.readFileSync(infile, "utf8"));
59
- } else {
60
- var code = "";
61
- process.stdin.resume();
62
- process.stdin.on("data", function (chunk) { return code += chunk; });
63
- process.stdin.on("end", function () { return run(code); });
64
- }
@@ -1,35 +0,0 @@
1
- {
2
- "name": "acorn",
3
- "description": "ECMAScript parser",
4
- "homepage": "https://github.com/acornjs/acorn",
5
- "main": "dist/acorn.js",
6
- "types": "dist/acorn.d.ts",
7
- "module": "dist/acorn.mjs",
8
- "version": "7.4.1",
9
- "engines": {"node": ">=0.4.0"},
10
- "maintainers": [
11
- {
12
- "name": "Marijn Haverbeke",
13
- "email": "marijnh@gmail.com",
14
- "web": "https://marijnhaverbeke.nl"
15
- },
16
- {
17
- "name": "Ingvar Stepanyan",
18
- "email": "me@rreverser.com",
19
- "web": "https://rreverser.com/"
20
- },
21
- {
22
- "name": "Adrian Heine",
23
- "web": "http://adrianheine.de"
24
- }
25
- ],
26
- "repository": {
27
- "type": "git",
28
- "url": "https://github.com/acornjs/acorn.git"
29
- },
30
- "license": "MIT",
31
- "scripts": {
32
- "prepare": "cd ..; npm run build:main && npm run build:bin"
33
- },
34
- "bin": {"acorn": "./bin/acorn"}
35
- }
@@ -1,19 +0,0 @@
1
- Copyright (C) 2012-2017 by Ingvar Stepanyan
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -1,40 +0,0 @@
1
- # Acorn-JSX
2
-
3
- [![Build Status](https://travis-ci.org/acornjs/acorn-jsx.svg?branch=master)](https://travis-ci.org/acornjs/acorn-jsx)
4
- [![NPM version](https://img.shields.io/npm/v/acorn-jsx.svg)](https://www.npmjs.org/package/acorn-jsx)
5
-
6
- This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
7
-
8
- It was created as an experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser. Later, it replaced the [official parser](https://github.com/facebookarchive/esprima) and these days is used by many prominent development tools.
9
-
10
- ## Transpiler
11
-
12
- Please note that this tool only parses source code to JSX AST, which is useful for various language tools and services. If you want to transpile your code to regular ES5-compliant JavaScript with source map, check out [Babel](https://babeljs.io/) and [Buble](https://buble.surge.sh/) transpilers which use `acorn-jsx` under the hood.
13
-
14
- ## Usage
15
-
16
- Requiring this module provides you with an Acorn plugin that you can use like this:
17
-
18
- ```javascript
19
- var acorn = require("acorn");
20
- var jsx = require("acorn-jsx");
21
- acorn.Parser.extend(jsx()).parse("my(<jsx/>, 'code');");
22
- ```
23
-
24
- Note that official spec doesn't support mix of XML namespaces and object-style access in tag names (#27) like in `<namespace:Object.Property />`, so it was deprecated in `acorn-jsx@3.0`. If you still want to opt-in to support of such constructions, you can pass the following option:
25
-
26
- ```javascript
27
- acorn.Parser.extend(jsx({ allowNamespacedObjects: true }))
28
- ```
29
-
30
- Also, since most apps use pure React transformer, a new option was introduced that allows to prohibit namespaces completely:
31
-
32
- ```javascript
33
- acorn.Parser.extend(jsx({ allowNamespaces: false }))
34
- ```
35
-
36
- Note that by default `allowNamespaces` is enabled for spec compliancy.
37
-
38
- ## License
39
-
40
- This plugin is issued under the [MIT license](./LICENSE).
@@ -1,488 +0,0 @@
1
- 'use strict';
2
-
3
- const XHTMLEntities = require('./xhtml');
4
-
5
- const hexNumber = /^[\da-fA-F]+$/;
6
- const decimalNumber = /^\d+$/;
7
-
8
- // The map to `acorn-jsx` tokens from `acorn` namespace objects.
9
- const acornJsxMap = new WeakMap();
10
-
11
- // Get the original tokens for the given `acorn` namespace object.
12
- function getJsxTokens(acorn) {
13
- acorn = acorn.Parser.acorn || acorn;
14
- let acornJsx = acornJsxMap.get(acorn);
15
- if (!acornJsx) {
16
- const tt = acorn.tokTypes;
17
- const TokContext = acorn.TokContext;
18
- const TokenType = acorn.TokenType;
19
- const tc_oTag = new TokContext('<tag', false);
20
- const tc_cTag = new TokContext('</tag', false);
21
- const tc_expr = new TokContext('<tag>...</tag>', true, true);
22
- const tokContexts = {
23
- tc_oTag: tc_oTag,
24
- tc_cTag: tc_cTag,
25
- tc_expr: tc_expr
26
- };
27
- const tokTypes = {
28
- jsxName: new TokenType('jsxName'),
29
- jsxText: new TokenType('jsxText', {beforeExpr: true}),
30
- jsxTagStart: new TokenType('jsxTagStart', {startsExpr: true}),
31
- jsxTagEnd: new TokenType('jsxTagEnd')
32
- };
33
-
34
- tokTypes.jsxTagStart.updateContext = function() {
35
- this.context.push(tc_expr); // treat as beginning of JSX expression
36
- this.context.push(tc_oTag); // start opening tag context
37
- this.exprAllowed = false;
38
- };
39
- tokTypes.jsxTagEnd.updateContext = function(prevType) {
40
- let out = this.context.pop();
41
- if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
42
- this.context.pop();
43
- this.exprAllowed = this.curContext() === tc_expr;
44
- } else {
45
- this.exprAllowed = true;
46
- }
47
- };
48
-
49
- acornJsx = { tokContexts: tokContexts, tokTypes: tokTypes };
50
- acornJsxMap.set(acorn, acornJsx);
51
- }
52
-
53
- return acornJsx;
54
- }
55
-
56
- // Transforms JSX element name to string.
57
-
58
- function getQualifiedJSXName(object) {
59
- if (!object)
60
- return object;
61
-
62
- if (object.type === 'JSXIdentifier')
63
- return object.name;
64
-
65
- if (object.type === 'JSXNamespacedName')
66
- return object.namespace.name + ':' + object.name.name;
67
-
68
- if (object.type === 'JSXMemberExpression')
69
- return getQualifiedJSXName(object.object) + '.' +
70
- getQualifiedJSXName(object.property);
71
- }
72
-
73
- module.exports = function(options) {
74
- options = options || {};
75
- return function(Parser) {
76
- return plugin({
77
- allowNamespaces: options.allowNamespaces !== false,
78
- allowNamespacedObjects: !!options.allowNamespacedObjects
79
- }, Parser);
80
- };
81
- };
82
-
83
- // This is `tokTypes` of the peer dep.
84
- // This can be different instances from the actual `tokTypes` this plugin uses.
85
- Object.defineProperty(module.exports, "tokTypes", {
86
- get: function get_tokTypes() {
87
- return getJsxTokens(require("acorn")).tokTypes;
88
- },
89
- configurable: true,
90
- enumerable: true
91
- });
92
-
93
- function plugin(options, Parser) {
94
- const acorn = Parser.acorn || require("acorn");
95
- const acornJsx = getJsxTokens(acorn);
96
- const tt = acorn.tokTypes;
97
- const tok = acornJsx.tokTypes;
98
- const tokContexts = acorn.tokContexts;
99
- const tc_oTag = acornJsx.tokContexts.tc_oTag;
100
- const tc_cTag = acornJsx.tokContexts.tc_cTag;
101
- const tc_expr = acornJsx.tokContexts.tc_expr;
102
- const isNewLine = acorn.isNewLine;
103
- const isIdentifierStart = acorn.isIdentifierStart;
104
- const isIdentifierChar = acorn.isIdentifierChar;
105
-
106
- return class extends Parser {
107
- // Expose actual `tokTypes` and `tokContexts` to other plugins.
108
- static get acornJsx() {
109
- return acornJsx;
110
- }
111
-
112
- // Reads inline JSX contents token.
113
- jsx_readToken() {
114
- let out = '', chunkStart = this.pos;
115
- for (;;) {
116
- if (this.pos >= this.input.length)
117
- this.raise(this.start, 'Unterminated JSX contents');
118
- let ch = this.input.charCodeAt(this.pos);
119
-
120
- switch (ch) {
121
- case 60: // '<'
122
- case 123: // '{'
123
- if (this.pos === this.start) {
124
- if (ch === 60 && this.exprAllowed) {
125
- ++this.pos;
126
- return this.finishToken(tok.jsxTagStart);
127
- }
128
- return this.getTokenFromCode(ch);
129
- }
130
- out += this.input.slice(chunkStart, this.pos);
131
- return this.finishToken(tok.jsxText, out);
132
-
133
- case 38: // '&'
134
- out += this.input.slice(chunkStart, this.pos);
135
- out += this.jsx_readEntity();
136
- chunkStart = this.pos;
137
- break;
138
-
139
- case 62: // '>'
140
- case 125: // '}'
141
- this.raise(
142
- this.pos,
143
- "Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
144
- (ch === 62 ? "&gt;" : "&rbrace;") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
145
- );
146
-
147
- default:
148
- if (isNewLine(ch)) {
149
- out += this.input.slice(chunkStart, this.pos);
150
- out += this.jsx_readNewLine(true);
151
- chunkStart = this.pos;
152
- } else {
153
- ++this.pos;
154
- }
155
- }
156
- }
157
- }
158
-
159
- jsx_readNewLine(normalizeCRLF) {
160
- let ch = this.input.charCodeAt(this.pos);
161
- let out;
162
- ++this.pos;
163
- if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
164
- ++this.pos;
165
- out = normalizeCRLF ? '\n' : '\r\n';
166
- } else {
167
- out = String.fromCharCode(ch);
168
- }
169
- if (this.options.locations) {
170
- ++this.curLine;
171
- this.lineStart = this.pos;
172
- }
173
-
174
- return out;
175
- }
176
-
177
- jsx_readString(quote) {
178
- let out = '', chunkStart = ++this.pos;
179
- for (;;) {
180
- if (this.pos >= this.input.length)
181
- this.raise(this.start, 'Unterminated string constant');
182
- let ch = this.input.charCodeAt(this.pos);
183
- if (ch === quote) break;
184
- if (ch === 38) { // '&'
185
- out += this.input.slice(chunkStart, this.pos);
186
- out += this.jsx_readEntity();
187
- chunkStart = this.pos;
188
- } else if (isNewLine(ch)) {
189
- out += this.input.slice(chunkStart, this.pos);
190
- out += this.jsx_readNewLine(false);
191
- chunkStart = this.pos;
192
- } else {
193
- ++this.pos;
194
- }
195
- }
196
- out += this.input.slice(chunkStart, this.pos++);
197
- return this.finishToken(tt.string, out);
198
- }
199
-
200
- jsx_readEntity() {
201
- let str = '', count = 0, entity;
202
- let ch = this.input[this.pos];
203
- if (ch !== '&')
204
- this.raise(this.pos, 'Entity must start with an ampersand');
205
- let startPos = ++this.pos;
206
- while (this.pos < this.input.length && count++ < 10) {
207
- ch = this.input[this.pos++];
208
- if (ch === ';') {
209
- if (str[0] === '#') {
210
- if (str[1] === 'x') {
211
- str = str.substr(2);
212
- if (hexNumber.test(str))
213
- entity = String.fromCharCode(parseInt(str, 16));
214
- } else {
215
- str = str.substr(1);
216
- if (decimalNumber.test(str))
217
- entity = String.fromCharCode(parseInt(str, 10));
218
- }
219
- } else {
220
- entity = XHTMLEntities[str];
221
- }
222
- break;
223
- }
224
- str += ch;
225
- }
226
- if (!entity) {
227
- this.pos = startPos;
228
- return '&';
229
- }
230
- return entity;
231
- }
232
-
233
- // Read a JSX identifier (valid tag or attribute name).
234
- //
235
- // Optimized version since JSX identifiers can't contain
236
- // escape characters and so can be read as single slice.
237
- // Also assumes that first character was already checked
238
- // by isIdentifierStart in readToken.
239
-
240
- jsx_readWord() {
241
- let ch, start = this.pos;
242
- do {
243
- ch = this.input.charCodeAt(++this.pos);
244
- } while (isIdentifierChar(ch) || ch === 45); // '-'
245
- return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
246
- }
247
-
248
- // Parse next token as JSX identifier
249
-
250
- jsx_parseIdentifier() {
251
- let node = this.startNode();
252
- if (this.type === tok.jsxName)
253
- node.name = this.value;
254
- else if (this.type.keyword)
255
- node.name = this.type.keyword;
256
- else
257
- this.unexpected();
258
- this.next();
259
- return this.finishNode(node, 'JSXIdentifier');
260
- }
261
-
262
- // Parse namespaced identifier.
263
-
264
- jsx_parseNamespacedName() {
265
- let startPos = this.start, startLoc = this.startLoc;
266
- let name = this.jsx_parseIdentifier();
267
- if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
268
- var node = this.startNodeAt(startPos, startLoc);
269
- node.namespace = name;
270
- node.name = this.jsx_parseIdentifier();
271
- return this.finishNode(node, 'JSXNamespacedName');
272
- }
273
-
274
- // Parses element name in any form - namespaced, member
275
- // or single identifier.
276
-
277
- jsx_parseElementName() {
278
- if (this.type === tok.jsxTagEnd) return '';
279
- let startPos = this.start, startLoc = this.startLoc;
280
- let node = this.jsx_parseNamespacedName();
281
- if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !options.allowNamespacedObjects) {
282
- this.unexpected();
283
- }
284
- while (this.eat(tt.dot)) {
285
- let newNode = this.startNodeAt(startPos, startLoc);
286
- newNode.object = node;
287
- newNode.property = this.jsx_parseIdentifier();
288
- node = this.finishNode(newNode, 'JSXMemberExpression');
289
- }
290
- return node;
291
- }
292
-
293
- // Parses any type of JSX attribute value.
294
-
295
- jsx_parseAttributeValue() {
296
- switch (this.type) {
297
- case tt.braceL:
298
- let node = this.jsx_parseExpressionContainer();
299
- if (node.expression.type === 'JSXEmptyExpression')
300
- this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
301
- return node;
302
-
303
- case tok.jsxTagStart:
304
- case tt.string:
305
- return this.parseExprAtom();
306
-
307
- default:
308
- this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
309
- }
310
- }
311
-
312
- // JSXEmptyExpression is unique type since it doesn't actually parse anything,
313
- // and so it should start at the end of last read token (left brace) and finish
314
- // at the beginning of the next one (right brace).
315
-
316
- jsx_parseEmptyExpression() {
317
- let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
318
- return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
319
- }
320
-
321
- // Parses JSX expression enclosed into curly brackets.
322
-
323
- jsx_parseExpressionContainer() {
324
- let node = this.startNode();
325
- this.next();
326
- node.expression = this.type === tt.braceR
327
- ? this.jsx_parseEmptyExpression()
328
- : this.parseExpression();
329
- this.expect(tt.braceR);
330
- return this.finishNode(node, 'JSXExpressionContainer');
331
- }
332
-
333
- // Parses following JSX attribute name-value pair.
334
-
335
- jsx_parseAttribute() {
336
- let node = this.startNode();
337
- if (this.eat(tt.braceL)) {
338
- this.expect(tt.ellipsis);
339
- node.argument = this.parseMaybeAssign();
340
- this.expect(tt.braceR);
341
- return this.finishNode(node, 'JSXSpreadAttribute');
342
- }
343
- node.name = this.jsx_parseNamespacedName();
344
- node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
345
- return this.finishNode(node, 'JSXAttribute');
346
- }
347
-
348
- // Parses JSX opening tag starting after '<'.
349
-
350
- jsx_parseOpeningElementAt(startPos, startLoc) {
351
- let node = this.startNodeAt(startPos, startLoc);
352
- node.attributes = [];
353
- let nodeName = this.jsx_parseElementName();
354
- if (nodeName) node.name = nodeName;
355
- while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
356
- node.attributes.push(this.jsx_parseAttribute());
357
- node.selfClosing = this.eat(tt.slash);
358
- this.expect(tok.jsxTagEnd);
359
- return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
360
- }
361
-
362
- // Parses JSX closing tag starting after '</'.
363
-
364
- jsx_parseClosingElementAt(startPos, startLoc) {
365
- let node = this.startNodeAt(startPos, startLoc);
366
- let nodeName = this.jsx_parseElementName();
367
- if (nodeName) node.name = nodeName;
368
- this.expect(tok.jsxTagEnd);
369
- return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
370
- }
371
-
372
- // Parses entire JSX element, including it's opening tag
373
- // (starting after '<'), attributes, contents and closing tag.
374
-
375
- jsx_parseElementAt(startPos, startLoc) {
376
- let node = this.startNodeAt(startPos, startLoc);
377
- let children = [];
378
- let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
379
- let closingElement = null;
380
-
381
- if (!openingElement.selfClosing) {
382
- contents: for (;;) {
383
- switch (this.type) {
384
- case tok.jsxTagStart:
385
- startPos = this.start; startLoc = this.startLoc;
386
- this.next();
387
- if (this.eat(tt.slash)) {
388
- closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
389
- break contents;
390
- }
391
- children.push(this.jsx_parseElementAt(startPos, startLoc));
392
- break;
393
-
394
- case tok.jsxText:
395
- children.push(this.parseExprAtom());
396
- break;
397
-
398
- case tt.braceL:
399
- children.push(this.jsx_parseExpressionContainer());
400
- break;
401
-
402
- default:
403
- this.unexpected();
404
- }
405
- }
406
- if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
407
- this.raise(
408
- closingElement.start,
409
- 'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
410
- }
411
- }
412
- let fragmentOrElement = openingElement.name ? 'Element' : 'Fragment';
413
-
414
- node['opening' + fragmentOrElement] = openingElement;
415
- node['closing' + fragmentOrElement] = closingElement;
416
- node.children = children;
417
- if (this.type === tt.relational && this.value === "<") {
418
- this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
419
- }
420
- return this.finishNode(node, 'JSX' + fragmentOrElement);
421
- }
422
-
423
- // Parse JSX text
424
-
425
- jsx_parseText() {
426
- let node = this.parseLiteral(this.value);
427
- node.type = "JSXText";
428
- return node;
429
- }
430
-
431
- // Parses entire JSX element from current position.
432
-
433
- jsx_parseElement() {
434
- let startPos = this.start, startLoc = this.startLoc;
435
- this.next();
436
- return this.jsx_parseElementAt(startPos, startLoc);
437
- }
438
-
439
- parseExprAtom(refShortHandDefaultPos) {
440
- if (this.type === tok.jsxText)
441
- return this.jsx_parseText();
442
- else if (this.type === tok.jsxTagStart)
443
- return this.jsx_parseElement();
444
- else
445
- return super.parseExprAtom(refShortHandDefaultPos);
446
- }
447
-
448
- readToken(code) {
449
- let context = this.curContext();
450
-
451
- if (context === tc_expr) return this.jsx_readToken();
452
-
453
- if (context === tc_oTag || context === tc_cTag) {
454
- if (isIdentifierStart(code)) return this.jsx_readWord();
455
-
456
- if (code == 62) {
457
- ++this.pos;
458
- return this.finishToken(tok.jsxTagEnd);
459
- }
460
-
461
- if ((code === 34 || code === 39) && context == tc_oTag)
462
- return this.jsx_readString(code);
463
- }
464
-
465
- if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
466
- ++this.pos;
467
- return this.finishToken(tok.jsxTagStart);
468
- }
469
- return super.readToken(code);
470
- }
471
-
472
- updateContext(prevType) {
473
- if (this.type == tt.braceL) {
474
- var curContext = this.curContext();
475
- if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
476
- else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
477
- else super.updateContext(prevType);
478
- this.exprAllowed = true;
479
- } else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
480
- this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
481
- this.context.push(tc_cTag); // reconsider as closing tag context
482
- this.exprAllowed = false;
483
- } else {
484
- return super.updateContext(prevType);
485
- }
486
- }
487
- };
488
- }
@@ -1,27 +0,0 @@
1
- {
2
- "name": "acorn-jsx",
3
- "description": "Modern, fast React.js JSX parser",
4
- "homepage": "https://github.com/acornjs/acorn-jsx",
5
- "version": "5.3.1",
6
- "maintainers": [
7
- {
8
- "name": "Ingvar Stepanyan",
9
- "email": "me@rreverser.com",
10
- "web": "http://rreverser.com/"
11
- }
12
- ],
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/acornjs/acorn-jsx"
16
- },
17
- "license": "MIT",
18
- "scripts": {
19
- "test": "node test/run.js"
20
- },
21
- "peerDependencies": {
22
- "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
23
- },
24
- "devDependencies": {
25
- "acorn": "^8.0.1"
26
- }
27
- }