less 4.4.2 → 4.6.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 (333) hide show
  1. package/bin/lessc +67 -58
  2. package/dist/less.js +14496 -11811
  3. package/dist/less.min.js +4 -4
  4. package/dist/less.min.js.map +1 -1
  5. package/lib/less/constants.js +5 -7
  6. package/lib/less/contexts.js +71 -56
  7. package/lib/less/data/colors.js +150 -153
  8. package/lib/less/data/index.js +4 -7
  9. package/lib/less/data/unit-conversions.js +2 -5
  10. package/lib/less/default-options.js +52 -23
  11. package/lib/less/deprecation.js +67 -0
  12. package/lib/less/environment/abstract-file-manager.js +62 -50
  13. package/lib/less/environment/abstract-plugin-loader.js +69 -46
  14. package/lib/less/environment/environment-api.ts +21 -0
  15. package/lib/less/environment/environment.js +34 -30
  16. package/lib/less/environment/file-manager-api.ts +77 -0
  17. package/lib/less/functions/boolean.js +13 -13
  18. package/lib/less/functions/color-blending.js +39 -31
  19. package/lib/less/functions/color.js +153 -137
  20. package/lib/less/functions/data-uri.js +73 -64
  21. package/lib/less/functions/default.js +9 -11
  22. package/lib/less/functions/function-caller.js +35 -34
  23. package/lib/less/functions/function-registry.js +16 -17
  24. package/lib/less/functions/index.js +33 -33
  25. package/lib/less/functions/list.js +88 -75
  26. package/lib/less/functions/math-helper.js +8 -11
  27. package/lib/less/functions/math.js +21 -21
  28. package/lib/less/functions/number.js +42 -53
  29. package/lib/less/functions/string.js +18 -22
  30. package/lib/less/functions/style.js +21 -20
  31. package/lib/less/functions/svg.js +83 -82
  32. package/lib/less/functions/types.js +28 -32
  33. package/lib/less/import-manager.js +73 -64
  34. package/lib/less/index.js +65 -65
  35. package/lib/less/less-error.js +65 -46
  36. package/lib/less/logger.js +11 -14
  37. package/lib/less/parse-tree.js +94 -38
  38. package/lib/less/parse.js +44 -44
  39. package/lib/less/parser/parser-input.js +152 -131
  40. package/lib/less/parser/parser.js +866 -672
  41. package/lib/less/plugin-manager.js +57 -46
  42. package/lib/less/render.js +17 -23
  43. package/lib/less/source-map-builder.js +52 -43
  44. package/lib/less/source-map-output.js +57 -44
  45. package/lib/less/transform-tree.js +40 -30
  46. package/lib/less/tree/anonymous.js +52 -28
  47. package/lib/less/tree/assignment.js +44 -27
  48. package/lib/less/tree/atrule-syntax.js +4 -6
  49. package/lib/less/tree/atrule.js +247 -140
  50. package/lib/less/tree/attribute.js +55 -24
  51. package/lib/less/tree/call.js +70 -42
  52. package/lib/less/tree/color.js +194 -145
  53. package/lib/less/tree/combinator.js +31 -21
  54. package/lib/less/tree/comment.js +44 -23
  55. package/lib/less/tree/condition.js +61 -36
  56. package/lib/less/tree/container.js +90 -34
  57. package/lib/less/tree/debug-info.js +53 -11
  58. package/lib/less/tree/declaration.js +97 -52
  59. package/lib/less/tree/detached-ruleset.js +42 -24
  60. package/lib/less/tree/dimension.js +127 -71
  61. package/lib/less/tree/element.js +82 -52
  62. package/lib/less/tree/expression.js +75 -50
  63. package/lib/less/tree/extend.js +71 -42
  64. package/lib/less/tree/import.js +184 -110
  65. package/lib/less/tree/index.js +52 -81
  66. package/lib/less/tree/javascript.js +43 -32
  67. package/lib/less/tree/js-eval-node.js +46 -32
  68. package/lib/less/tree/keyword.js +25 -17
  69. package/lib/less/tree/media.js +77 -35
  70. package/lib/less/tree/merge-rules.js +47 -0
  71. package/lib/less/tree/mixin-call.js +181 -98
  72. package/lib/less/tree/mixin-definition.js +211 -117
  73. package/lib/less/tree/namespace-value.js +63 -44
  74. package/lib/less/tree/negative.js +34 -21
  75. package/lib/less/tree/nested-at-rule.js +149 -66
  76. package/lib/less/tree/node.js +225 -90
  77. package/lib/less/tree/operation.js +59 -34
  78. package/lib/less/tree/paren.js +34 -17
  79. package/lib/less/tree/property.js +66 -35
  80. package/lib/less/tree/query-in-parens.js +52 -60
  81. package/lib/less/tree/quoted.js +93 -44
  82. package/lib/less/tree/ruleset.js +632 -318
  83. package/lib/less/tree/selector.js +151 -77
  84. package/lib/less/tree/unicode-descriptor.js +14 -12
  85. package/lib/less/tree/unit.js +111 -63
  86. package/lib/less/tree/url.js +62 -38
  87. package/lib/less/tree/value.js +50 -34
  88. package/lib/less/tree/variable-call.js +47 -30
  89. package/lib/less/tree/variable.js +53 -31
  90. package/lib/less/utils.js +44 -47
  91. package/lib/less/visitors/extend-visitor.js +233 -172
  92. package/lib/less/visitors/import-sequencer.js +24 -24
  93. package/lib/less/visitors/import-visitor.js +62 -52
  94. package/lib/less/visitors/index.js +14 -17
  95. package/lib/less/visitors/join-selector-visitor.js +40 -37
  96. package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
  97. package/lib/less/visitors/to-css-visitor.js +135 -128
  98. package/lib/less/visitors/visitor.js +60 -45
  99. package/lib/less-browser/add-default-options.js +23 -13
  100. package/lib/less-browser/bootstrap.js +23 -17
  101. package/lib/less-browser/browser.js +24 -21
  102. package/lib/less-browser/cache.js +17 -19
  103. package/lib/less-browser/error-reporting.js +52 -44
  104. package/lib/less-browser/file-manager.js +52 -42
  105. package/lib/less-browser/image-size.js +12 -12
  106. package/lib/less-browser/index.js +131 -105
  107. package/lib/less-browser/log-listener.js +30 -31
  108. package/lib/less-browser/plugin-loader.js +10 -10
  109. package/lib/less-browser/utils.js +19 -21
  110. package/lib/less-node/environment.js +32 -8
  111. package/lib/less-node/file-manager.js +62 -45
  112. package/lib/less-node/fs.js +11 -8
  113. package/lib/less-node/image-size.js +40 -31
  114. package/lib/less-node/index.js +28 -19
  115. package/lib/less-node/lessc-helper.js +28 -28
  116. package/lib/less-node/plugin-loader.js +35 -27
  117. package/lib/less-node/url-file-manager.js +33 -31
  118. package/package.json +31 -19
  119. package/.eslintignore +0 -6
  120. package/.eslintrc.js +0 -63
  121. package/Gruntfile.js +0 -404
  122. package/bower.json +0 -22
  123. package/lib/less/constants.js.map +0 -1
  124. package/lib/less/contexts.js.map +0 -1
  125. package/lib/less/data/colors.js.map +0 -1
  126. package/lib/less/data/index.js.map +0 -1
  127. package/lib/less/data/unit-conversions.js.map +0 -1
  128. package/lib/less/default-options.js.map +0 -1
  129. package/lib/less/environment/abstract-file-manager.js.map +0 -1
  130. package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
  131. package/lib/less/environment/environment-api.js +0 -3
  132. package/lib/less/environment/environment-api.js.map +0 -1
  133. package/lib/less/environment/environment.js.map +0 -1
  134. package/lib/less/environment/file-manager-api.js +0 -3
  135. package/lib/less/environment/file-manager-api.js.map +0 -1
  136. package/lib/less/functions/boolean.js.map +0 -1
  137. package/lib/less/functions/color-blending.js.map +0 -1
  138. package/lib/less/functions/color.js.map +0 -1
  139. package/lib/less/functions/data-uri.js.map +0 -1
  140. package/lib/less/functions/default.js.map +0 -1
  141. package/lib/less/functions/function-caller.js.map +0 -1
  142. package/lib/less/functions/function-registry.js.map +0 -1
  143. package/lib/less/functions/index.js.map +0 -1
  144. package/lib/less/functions/list.js.map +0 -1
  145. package/lib/less/functions/math-helper.js.map +0 -1
  146. package/lib/less/functions/math.js.map +0 -1
  147. package/lib/less/functions/number.js.map +0 -1
  148. package/lib/less/functions/string.js.map +0 -1
  149. package/lib/less/functions/style.js.map +0 -1
  150. package/lib/less/functions/svg.js.map +0 -1
  151. package/lib/less/functions/types.js.map +0 -1
  152. package/lib/less/import-manager.js.map +0 -1
  153. package/lib/less/index.js.map +0 -1
  154. package/lib/less/less-error.js.map +0 -1
  155. package/lib/less/logger.js.map +0 -1
  156. package/lib/less/parse-tree.js.map +0 -1
  157. package/lib/less/parse.js.map +0 -1
  158. package/lib/less/parser/chunker.js +0 -148
  159. package/lib/less/parser/chunker.js.map +0 -1
  160. package/lib/less/parser/parser-input.js.map +0 -1
  161. package/lib/less/parser/parser.js.map +0 -1
  162. package/lib/less/plugin-manager.js.map +0 -1
  163. package/lib/less/render.js.map +0 -1
  164. package/lib/less/source-map-builder.js.map +0 -1
  165. package/lib/less/source-map-output.js.map +0 -1
  166. package/lib/less/transform-tree.js.map +0 -1
  167. package/lib/less/tree/anonymous.js.map +0 -1
  168. package/lib/less/tree/assignment.js.map +0 -1
  169. package/lib/less/tree/atrule-syntax.js.map +0 -1
  170. package/lib/less/tree/atrule.js.map +0 -1
  171. package/lib/less/tree/attribute.js.map +0 -1
  172. package/lib/less/tree/call.js.map +0 -1
  173. package/lib/less/tree/color.js.map +0 -1
  174. package/lib/less/tree/combinator.js.map +0 -1
  175. package/lib/less/tree/comment.js.map +0 -1
  176. package/lib/less/tree/condition.js.map +0 -1
  177. package/lib/less/tree/container.js.map +0 -1
  178. package/lib/less/tree/debug-info.js.map +0 -1
  179. package/lib/less/tree/declaration.js.map +0 -1
  180. package/lib/less/tree/detached-ruleset.js.map +0 -1
  181. package/lib/less/tree/dimension.js.map +0 -1
  182. package/lib/less/tree/element.js.map +0 -1
  183. package/lib/less/tree/expression.js.map +0 -1
  184. package/lib/less/tree/extend.js.map +0 -1
  185. package/lib/less/tree/import.js.map +0 -1
  186. package/lib/less/tree/index.js.map +0 -1
  187. package/lib/less/tree/javascript.js.map +0 -1
  188. package/lib/less/tree/js-eval-node.js.map +0 -1
  189. package/lib/less/tree/keyword.js.map +0 -1
  190. package/lib/less/tree/media.js.map +0 -1
  191. package/lib/less/tree/mixin-call.js.map +0 -1
  192. package/lib/less/tree/mixin-definition.js.map +0 -1
  193. package/lib/less/tree/namespace-value.js.map +0 -1
  194. package/lib/less/tree/negative.js.map +0 -1
  195. package/lib/less/tree/nested-at-rule.js.map +0 -1
  196. package/lib/less/tree/node.js.map +0 -1
  197. package/lib/less/tree/operation.js.map +0 -1
  198. package/lib/less/tree/paren.js.map +0 -1
  199. package/lib/less/tree/property.js.map +0 -1
  200. package/lib/less/tree/query-in-parens.js.map +0 -1
  201. package/lib/less/tree/quoted.js.map +0 -1
  202. package/lib/less/tree/ruleset.js.map +0 -1
  203. package/lib/less/tree/selector.js.map +0 -1
  204. package/lib/less/tree/unicode-descriptor.js.map +0 -1
  205. package/lib/less/tree/unit.js.map +0 -1
  206. package/lib/less/tree/url.js.map +0 -1
  207. package/lib/less/tree/value.js.map +0 -1
  208. package/lib/less/tree/variable-call.js.map +0 -1
  209. package/lib/less/tree/variable.js.map +0 -1
  210. package/lib/less/utils.js.map +0 -1
  211. package/lib/less/visitors/extend-visitor.js.map +0 -1
  212. package/lib/less/visitors/import-sequencer.js.map +0 -1
  213. package/lib/less/visitors/import-visitor.js.map +0 -1
  214. package/lib/less/visitors/index.js.map +0 -1
  215. package/lib/less/visitors/join-selector-visitor.js.map +0 -1
  216. package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
  217. package/lib/less/visitors/to-css-visitor.js.map +0 -1
  218. package/lib/less/visitors/visitor.js.map +0 -1
  219. package/lib/less-browser/add-default-options.js.map +0 -1
  220. package/lib/less-browser/bootstrap.js.map +0 -1
  221. package/lib/less-browser/browser.js.map +0 -1
  222. package/lib/less-browser/cache.js.map +0 -1
  223. package/lib/less-browser/error-reporting.js.map +0 -1
  224. package/lib/less-browser/file-manager.js.map +0 -1
  225. package/lib/less-browser/image-size.js.map +0 -1
  226. package/lib/less-browser/index.js.map +0 -1
  227. package/lib/less-browser/log-listener.js.map +0 -1
  228. package/lib/less-browser/plugin-loader.js.map +0 -1
  229. package/lib/less-browser/utils.js.map +0 -1
  230. package/lib/less-node/environment.js.map +0 -1
  231. package/lib/less-node/file-manager.js.map +0 -1
  232. package/lib/less-node/fs.js.map +0 -1
  233. package/lib/less-node/image-size.js.map +0 -1
  234. package/lib/less-node/index.js.map +0 -1
  235. package/lib/less-node/lessc-helper.js.map +0 -1
  236. package/lib/less-node/plugin-loader.js.map +0 -1
  237. package/lib/less-node/url-file-manager.js.map +0 -1
  238. package/test/.eslintrc.json +0 -9
  239. package/test/README.md +0 -3
  240. package/test/browser/common.js +0 -230
  241. package/test/browser/css/global-vars/simple.css +0 -3
  242. package/test/browser/css/modify-vars/simple.css +0 -8
  243. package/test/browser/css/plugin/plugin.css +0 -3
  244. package/test/browser/css/postProcessor/postProcessor.css +0 -4
  245. package/test/browser/css/relative-urls/urls.css +0 -36
  246. package/test/browser/css/rewrite-urls/urls.css +0 -36
  247. package/test/browser/css/rootpath/urls.css +0 -35
  248. package/test/browser/css/rootpath-relative/urls.css +0 -35
  249. package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
  250. package/test/browser/css/urls.css +0 -54
  251. package/test/browser/generator/benchmark.config.js +0 -50
  252. package/test/browser/generator/generate.js +0 -78
  253. package/test/browser/generator/runner.config.js +0 -188
  254. package/test/browser/generator/runner.js +0 -2
  255. package/test/browser/generator/template.js +0 -93
  256. package/test/browser/generator/utils.js +0 -14
  257. package/test/browser/less/console-errors/test-error.less +0 -3
  258. package/test/browser/less/console-errors/test-error.txt +0 -2
  259. package/test/browser/less/errors/image-height-error.less +0 -3
  260. package/test/browser/less/errors/image-height-error.txt +0 -4
  261. package/test/browser/less/errors/image-size-error.less +0 -3
  262. package/test/browser/less/errors/image-size-error.txt +0 -4
  263. package/test/browser/less/errors/image-width-error.less +0 -3
  264. package/test/browser/less/errors/image-width-error.txt +0 -4
  265. package/test/browser/less/global-vars/simple.less +0 -3
  266. package/test/browser/less/imports/urls.less +0 -4
  267. package/test/browser/less/imports/urls2.less +0 -4
  268. package/test/browser/less/modify-vars/imports/simple2.less +0 -4
  269. package/test/browser/less/modify-vars/simple.less +0 -8
  270. package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  271. package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  272. package/test/browser/less/plugin/plugin.js +0 -4
  273. package/test/browser/less/plugin/plugin.less +0 -4
  274. package/test/browser/less/postProcessor/postProcessor.less +0 -4
  275. package/test/browser/less/relative-urls/urls.less +0 -34
  276. package/test/browser/less/rewrite-urls/urls.less +0 -34
  277. package/test/browser/less/rootpath/urls.less +0 -33
  278. package/test/browser/less/rootpath-relative/urls.less +0 -33
  279. package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
  280. package/test/browser/less/urls.less +0 -62
  281. package/test/browser/runner-VisitorPlugin-options.js +0 -3
  282. package/test/browser/runner-VisitorPlugin.js +0 -3
  283. package/test/browser/runner-browser-options.js +0 -51
  284. package/test/browser/runner-browser-spec.js +0 -12
  285. package/test/browser/runner-console-errors.js +0 -5
  286. package/test/browser/runner-errors-options.js +0 -6
  287. package/test/browser/runner-errors-spec.js +0 -3
  288. package/test/browser/runner-filemanagerPlugin-options.js +0 -5
  289. package/test/browser/runner-filemanagerPlugin.js +0 -3
  290. package/test/browser/runner-global-vars-options.js +0 -7
  291. package/test/browser/runner-global-vars-spec.js +0 -3
  292. package/test/browser/runner-legacy-options.js +0 -6
  293. package/test/browser/runner-legacy-spec.js +0 -3
  294. package/test/browser/runner-main-options.js +0 -17
  295. package/test/browser/runner-main-spec.js +0 -7
  296. package/test/browser/runner-modify-vars-options.js +0 -5
  297. package/test/browser/runner-modify-vars-spec.js +0 -33
  298. package/test/browser/runner-no-js-errors-options.js +0 -4
  299. package/test/browser/runner-no-js-errors-spec.js +0 -3
  300. package/test/browser/runner-postProcessorPlugin-options.js +0 -3
  301. package/test/browser/runner-postProcessorPlugin.js +0 -3
  302. package/test/browser/runner-preProcessorPlugin-options.js +0 -3
  303. package/test/browser/runner-preProcessorPlugin.js +0 -3
  304. package/test/browser/runner-production-options.js +0 -3
  305. package/test/browser/runner-production-spec.js +0 -5
  306. package/test/browser/runner-relative-urls-options.js +0 -3
  307. package/test/browser/runner-relative-urls-spec.js +0 -3
  308. package/test/browser/runner-rewrite-urls-options.js +0 -3
  309. package/test/browser/runner-rewrite-urls-spec.js +0 -3
  310. package/test/browser/runner-rootpath-options.js +0 -3
  311. package/test/browser/runner-rootpath-relative-options.js +0 -4
  312. package/test/browser/runner-rootpath-relative-spec.js +0 -3
  313. package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
  314. package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
  315. package/test/browser/runner-rootpath-spec.js +0 -3
  316. package/test/browser/runner-strict-units-options.js +0 -5
  317. package/test/browser/runner-strict-units-spec.js +0 -3
  318. package/test/index.js +0 -112
  319. package/test/less-test.js +0 -625
  320. package/test/mocha-playwright/runner.js +0 -210
  321. package/test/modify-vars.js +0 -28
  322. package/test/plugins/filemanager/index.js +0 -19
  323. package/test/plugins/postprocess/index.js +0 -14
  324. package/test/plugins/preprocess/index.js +0 -19
  325. package/test/plugins/visitor/index.js +0 -24
  326. package/test/sourcemaps/basic.json +0 -1
  327. package/test/sourcemaps/custom-props.json +0 -1
  328. package/test/sourcemaps/index.html +0 -17
  329. package/test/sourcemaps-disable-annotation/basic.json +0 -1
  330. package/test/sourcemaps-variable-selector/basic.json +0 -1
  331. package/test/test-es6.ts +0 -17
  332. package/tsconfig.build.json +0 -7
  333. package/tsconfig.json +0 -21
@@ -1,64 +1,70 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var chunker_1 = tslib_1.__importDefault(require("./chunker"));
5
- exports.default = (function () {
6
- var // Less input string
7
- input;
8
- var // current chunk
9
- j;
10
- var // holds state for backtracking
11
- saveStack = [];
12
- var // furthest index the parser has gone to
13
- furthest;
14
- var // if this is furthest we got to, this is the probably cause
15
- furthestPossibleErrorMessage;
16
- var // chunkified input
17
- chunks;
18
- var // current chunk
19
- current;
20
- var // index of current chunk, in `input`
21
- currentPos;
22
- var parserInput = {};
23
- var CHARCODE_SPACE = 32;
24
- var CHARCODE_TAB = 9;
25
- var CHARCODE_LF = 10;
26
- var CHARCODE_CR = 13;
27
- var CHARCODE_PLUS = 43;
28
- var CHARCODE_COMMA = 44;
29
- var CHARCODE_FORWARD_SLASH = 47;
30
- var CHARCODE_9 = 57;
1
+ export default () => {
2
+ let // Less input string
3
+ input;
4
+
5
+ let // current chunk
6
+ j;
7
+
8
+ const // holds state for backtracking
9
+ saveStack = [];
10
+
11
+ let // furthest index the parser has gone to
12
+ furthest;
13
+
14
+ let // if this is furthest we got to, this is the probably cause
15
+ furthestPossibleErrorMessage;
16
+
17
+ let // chunkified input
18
+ chunks;
19
+
20
+ let // current chunk
21
+ current;
22
+
23
+ let // index of current chunk, in `input`
24
+ currentPos;
25
+
26
+ const parserInput = {};
27
+ const CHARCODE_SPACE = 32;
28
+ const CHARCODE_TAB = 9;
29
+ const CHARCODE_LF = 10;
30
+ const CHARCODE_CR = 13;
31
+ const CHARCODE_PLUS = 43;
32
+ const CHARCODE_COMMA = 44;
33
+ const CHARCODE_FORWARD_SLASH = 47;
34
+ const CHARCODE_9 = 57;
35
+
31
36
  function skipWhitespace(length) {
32
- var oldi = parserInput.i;
33
- var oldj = j;
34
- var curr = parserInput.i - currentPos;
35
- var endIndex = parserInput.i + current.length - curr;
36
- var mem = (parserInput.i += length);
37
- var inp = input;
38
- var c;
39
- var nextChar;
40
- var comment;
37
+ const oldi = parserInput.i;
38
+ const oldj = j;
39
+ const curr = parserInput.i - currentPos;
40
+ const endIndex = parserInput.i + current.length - curr;
41
+ const mem = (parserInput.i += length);
42
+ const inp = input;
43
+ let c;
44
+ let nextChar;
45
+ let comment;
46
+
41
47
  for (; parserInput.i < endIndex; parserInput.i++) {
42
48
  c = inp.charCodeAt(parserInput.i);
49
+
43
50
  if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
44
51
  nextChar = inp.charAt(parserInput.i + 1);
45
52
  if (nextChar === '/') {
46
- comment = { index: parserInput.i, isLineComment: true };
47
- var nextNewLine = inp.indexOf('\n', parserInput.i + 2);
53
+ comment = {index: parserInput.i, isLineComment: true};
54
+ let nextNewLine = inp.indexOf('\n', parserInput.i + 2);
48
55
  if (nextNewLine < 0) {
49
56
  nextNewLine = endIndex;
50
57
  }
51
58
  parserInput.i = nextNewLine;
52
- comment.text = inp.substr(comment.index, parserInput.i - comment.index);
59
+ comment.text = inp.slice(comment.index, parserInput.i);
53
60
  parserInput.commentStore.push(comment);
54
61
  continue;
55
- }
56
- else if (nextChar === '*') {
57
- var nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
62
+ } else if (nextChar === '*') {
63
+ const nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
58
64
  if (nextStarSlash >= 0) {
59
65
  comment = {
60
66
  index: parserInput.i,
61
- text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
67
+ text: inp.slice(parserInput.i, nextStarSlash + 2),
62
68
  isLineComment: false
63
69
  };
64
70
  parserInput.i += comment.text.length - 1;
@@ -68,12 +74,15 @@ exports.default = (function () {
68
74
  }
69
75
  break;
70
76
  }
77
+
71
78
  if ((c !== CHARCODE_SPACE) && (c !== CHARCODE_LF) && (c !== CHARCODE_TAB) && (c !== CHARCODE_CR)) {
72
79
  break;
73
80
  }
74
81
  }
82
+
75
83
  current = current.slice(length + parserInput.i - mem + curr);
76
84
  currentPos = parserInput.i;
85
+
77
86
  if (!current.length) {
78
87
  if (j < chunks.length - 1) {
79
88
  current = chunks[++j];
@@ -82,80 +91,95 @@ exports.default = (function () {
82
91
  }
83
92
  parserInput.finished = true;
84
93
  }
94
+
85
95
  return oldi !== parserInput.i || oldj !== j;
86
96
  }
87
- parserInput.save = function () {
97
+
98
+ parserInput.save = () => {
88
99
  currentPos = parserInput.i;
89
- saveStack.push({ current: current, i: parserInput.i, j: j });
100
+ saveStack.push( { current, i: parserInput.i, j });
90
101
  };
91
- parserInput.restore = function (possibleErrorMessage) {
102
+ parserInput.restore = possibleErrorMessage => {
103
+
92
104
  if (parserInput.i > furthest || (parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage)) {
93
105
  furthest = parserInput.i;
94
106
  furthestPossibleErrorMessage = possibleErrorMessage;
95
107
  }
96
- var state = saveStack.pop();
108
+ const state = saveStack.pop();
97
109
  current = state.current;
98
110
  currentPos = parserInput.i = state.i;
99
111
  j = state.j;
100
112
  };
101
- parserInput.forget = function () {
113
+ parserInput.forget = () => {
102
114
  saveStack.pop();
103
115
  };
104
- parserInput.isWhitespace = function (offset) {
105
- var pos = parserInput.i + (offset || 0);
106
- var code = input.charCodeAt(pos);
116
+ parserInput.isWhitespace = offset => {
117
+ const pos = parserInput.i + (offset || 0);
118
+ const code = input.charCodeAt(pos);
107
119
  return (code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF);
108
120
  };
121
+
109
122
  // Specialization of $(tok)
110
- parserInput.$re = function (tok) {
123
+ parserInput.$re = tok => {
111
124
  if (parserInput.i > currentPos) {
112
125
  current = current.slice(parserInput.i - currentPos);
113
126
  currentPos = parserInput.i;
114
127
  }
115
- var m = tok.exec(current);
128
+
129
+ const m = tok.exec(current);
116
130
  if (!m) {
117
131
  return null;
118
132
  }
133
+
119
134
  skipWhitespace(m[0].length);
120
135
  if (typeof m === 'string') {
121
136
  return m;
122
137
  }
138
+
123
139
  return m.length === 1 ? m[0] : m;
124
140
  };
125
- parserInput.$char = function (tok) {
141
+
142
+ parserInput.$char = tok => {
126
143
  if (input.charAt(parserInput.i) !== tok) {
127
144
  return null;
128
145
  }
129
146
  skipWhitespace(1);
130
147
  return tok;
131
148
  };
132
- parserInput.$peekChar = function (tok) {
149
+
150
+ parserInput.$peekChar = tok => {
133
151
  if (input.charAt(parserInput.i) !== tok) {
134
152
  return null;
135
153
  }
136
154
  return tok;
137
155
  };
138
- parserInput.$str = function (tok) {
139
- var tokLength = tok.length;
156
+
157
+ parserInput.$str = tok => {
158
+ const tokLength = tok.length;
159
+
140
160
  // https://jsperf.com/string-startswith/21
141
- for (var i = 0; i < tokLength; i++) {
161
+ for (let i = 0; i < tokLength; i++) {
142
162
  if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
143
163
  return null;
144
164
  }
145
165
  }
166
+
146
167
  skipWhitespace(tokLength);
147
168
  return tok;
148
169
  };
149
- parserInput.$quoted = function (loc) {
150
- var pos = loc || parserInput.i;
151
- var startChar = input.charAt(pos);
170
+
171
+ parserInput.$quoted = loc => {
172
+ const pos = loc || parserInput.i;
173
+ const startChar = input.charAt(pos);
174
+
152
175
  if (startChar !== '\'' && startChar !== '"') {
153
176
  return;
154
177
  }
155
- var length = input.length;
156
- var currentPosition = pos;
157
- for (var i = 1; i + currentPosition < length; i++) {
158
- var nextChar = input.charAt(i + currentPosition);
178
+ const length = input.length;
179
+ const currentPosition = pos;
180
+
181
+ for (let i = 1; i + currentPosition < length; i++) {
182
+ const nextChar = input.charAt(i + currentPosition);
159
183
  switch (nextChar) {
160
184
  case '\\':
161
185
  i++;
@@ -164,10 +188,10 @@ exports.default = (function () {
164
188
  case '\n':
165
189
  break;
166
190
  case startChar: {
167
- var str = input.substr(currentPosition, i + 1);
191
+ const str = input.slice(currentPosition, currentPosition + i + 1);
168
192
  if (!loc && loc !== 0) {
169
193
  skipWhitespace(i + 1);
170
- return str;
194
+ return str
171
195
  }
172
196
  return [startChar, str];
173
197
  }
@@ -176,33 +200,35 @@ exports.default = (function () {
176
200
  }
177
201
  return null;
178
202
  };
203
+
179
204
  /**
180
205
  * Permissive parsing. Ignores everything except matching {} [] () and quotes
181
206
  * until matching token (outside of blocks)
182
207
  */
183
- parserInput.$parseUntil = function (tok) {
184
- var quote = '';
185
- var returnVal = null;
186
- var inComment = false;
187
- var blockDepth = 0;
188
- var blockStack = [];
189
- var parseGroups = [];
190
- var length = input.length;
191
- var startPos = parserInput.i;
192
- var lastPos = parserInput.i;
193
- var i = parserInput.i;
194
- var loop = true;
195
- var testChar;
208
+ parserInput.$parseUntil = tok => {
209
+ let quote = '';
210
+ let returnVal = null;
211
+ let inComment = false;
212
+ let blockDepth = 0;
213
+ const blockStack = [];
214
+ const parseGroups = [];
215
+ const length = input.length;
216
+ const startPos = parserInput.i;
217
+ let lastPos = parserInput.i;
218
+ let i = parserInput.i;
219
+ let loop = true;
220
+ let testChar;
221
+
196
222
  if (typeof tok === 'string') {
197
- testChar = function (char) { return char === tok; };
198
- }
199
- else {
200
- testChar = function (char) { return tok.test(char); };
223
+ testChar = char => char === tok
224
+ } else {
225
+ testChar = char => tok.test(char)
201
226
  }
227
+
202
228
  do {
203
- var nextChar = input.charAt(i);
229
+ let nextChar = input.charAt(i);
204
230
  if (blockDepth === 0 && testChar(nextChar)) {
205
- returnVal = input.substr(lastPos, i - lastPos);
231
+ returnVal = input.slice(lastPos, i);
206
232
  if (returnVal) {
207
233
  parseGroups.push(returnVal);
208
234
  }
@@ -211,9 +237,8 @@ exports.default = (function () {
211
237
  }
212
238
  returnVal = parseGroups;
213
239
  skipWhitespace(i - startPos);
214
- loop = false;
215
- }
216
- else {
240
+ loop = false
241
+ } else {
217
242
  if (inComment) {
218
243
  if (nextChar === '*' &&
219
244
  input.charAt(i + 1) === '/') {
@@ -228,7 +253,7 @@ exports.default = (function () {
228
253
  case '\\':
229
254
  i++;
230
255
  nextChar = input.charAt(i);
231
- parseGroups.push(input.substr(lastPos, i - lastPos + 1));
256
+ parseGroups.push(input.slice(lastPos, i + 1));
232
257
  lastPos = i + 1;
233
258
  break;
234
259
  case '/':
@@ -242,7 +267,7 @@ exports.default = (function () {
242
267
  case '"':
243
268
  quote = parserInput.$quoted(i);
244
269
  if (quote) {
245
- parseGroups.push(input.substr(lastPos, i - lastPos), quote);
270
+ parseGroups.push(input.slice(lastPos, i), quote);
246
271
  i += quote[1].length - 1;
247
272
  lastPos = i + 1;
248
273
  }
@@ -267,11 +292,10 @@ exports.default = (function () {
267
292
  case '}':
268
293
  case ')':
269
294
  case ']': {
270
- var expected = blockStack.pop();
295
+ const expected = blockStack.pop();
271
296
  if (nextChar === expected) {
272
297
  blockDepth--;
273
- }
274
- else {
298
+ } else {
275
299
  // move the parser to the error and return expected
276
300
  skipWhitespace(i - startPos);
277
301
  returnVal = expected;
@@ -285,75 +309,72 @@ exports.default = (function () {
285
309
  }
286
310
  }
287
311
  } while (loop);
312
+
288
313
  return returnVal ? returnVal : null;
289
- };
314
+ }
315
+
290
316
  parserInput.autoCommentAbsorb = true;
291
317
  parserInput.commentStore = [];
292
318
  parserInput.finished = false;
319
+
293
320
  // Same as $(), but don't change the state of the parser,
294
321
  // just return the match.
295
- parserInput.peek = function (tok) {
322
+ parserInput.peek = tok => {
296
323
  if (typeof tok === 'string') {
297
324
  // https://jsperf.com/string-startswith/21
298
- for (var i = 0; i < tok.length; i++) {
325
+ for (let i = 0; i < tok.length; i++) {
299
326
  if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
300
327
  return false;
301
328
  }
302
329
  }
303
330
  return true;
304
- }
305
- else {
331
+ } else {
306
332
  return tok.test(current);
307
333
  }
308
334
  };
335
+
309
336
  // Specialization of peek()
310
337
  // TODO remove or change some currentChar calls to peekChar
311
- parserInput.peekChar = function (tok) { return input.charAt(parserInput.i) === tok; };
312
- parserInput.currentChar = function () { return input.charAt(parserInput.i); };
313
- parserInput.prevChar = function () { return input.charAt(parserInput.i - 1); };
314
- parserInput.getInput = function () { return input; };
315
- parserInput.peekNotNumeric = function () {
316
- var c = input.charCodeAt(parserInput.i);
338
+ parserInput.peekChar = tok => input.charAt(parserInput.i) === tok;
339
+
340
+ parserInput.currentChar = () => input.charAt(parserInput.i);
341
+
342
+ parserInput.prevChar = () => input.charAt(parserInput.i - 1);
343
+
344
+ parserInput.getInput = () => input;
345
+
346
+ parserInput.peekNotNumeric = () => {
347
+ const c = input.charCodeAt(parserInput.i);
317
348
  // Is the first char of the dimension 0-9, '.', '+' or '-'
318
349
  return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
319
350
  };
320
- parserInput.start = function (str, chunkInput, failFunction) {
351
+
352
+ parserInput.start = (str) => {
321
353
  input = str;
322
354
  parserInput.i = j = currentPos = furthest = 0;
323
- // chunking apparently makes things quicker (but my tests indicate
324
- // it might actually make things slower in node at least)
325
- // and it is a non-perfect parse - it can't recognise
326
- // unquoted urls, meaning it can't distinguish comments
327
- // meaning comments with quotes or {}() in them get 'counted'
328
- // and then lead to parse errors.
329
- // In addition if the chunking chunks in the wrong place we might
330
- // not be able to parse a parser statement in one go
331
- // this is officially deprecated but can be switched on via an option
332
- // in the case it causes too much performance issues.
333
- if (chunkInput) {
334
- chunks = (0, chunker_1.default)(str, failFunction);
335
- }
336
- else {
337
- chunks = [str];
338
- }
355
+
356
+ chunks = [str];
339
357
  current = chunks[0];
358
+
340
359
  skipWhitespace(0);
341
360
  };
342
- parserInput.end = function () {
343
- var message;
344
- var isFinished = parserInput.i >= input.length;
361
+
362
+ parserInput.end = () => {
363
+ let message;
364
+ const isFinished = parserInput.i >= input.length;
365
+
345
366
  if (parserInput.i < furthest) {
346
367
  message = furthestPossibleErrorMessage;
347
368
  parserInput.i = furthest;
348
369
  }
349
370
  return {
350
- isFinished: isFinished,
371
+ isFinished,
351
372
  furthest: parserInput.i,
352
373
  furthestPossibleErrorMessage: message,
353
374
  furthestReachedEnd: parserInput.i >= input.length - 1,
354
375
  furthestChar: input[parserInput.i]
355
376
  };
356
377
  };
378
+
357
379
  return parserInput;
358
- });
359
- //# sourceMappingURL=parser-input.js.map
380
+ };