less 3.10.0-beta.2 → 3.10.3

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 (124) hide show
  1. package/.DS_Store +0 -0
  2. package/bin/lessc +6652 -5505
  3. package/dist/less.cjs.js +6593 -5448
  4. package/dist/less.js +10 -6
  5. package/dist/less.min.js +2 -2
  6. package/dist/less.min.js.map +1 -1
  7. package/lib/less/constants.js +13 -0
  8. package/lib/less/contexts.js +164 -0
  9. package/lib/less/data/colors.js +150 -0
  10. package/lib/less/data/index.js +4 -0
  11. package/lib/less/data/unit-conversions.js +21 -0
  12. package/lib/less/default-options.js +68 -0
  13. package/lib/less/environment/abstract-file-manager.js +127 -0
  14. package/lib/less/environment/abstract-plugin-loader.js +187 -0
  15. package/lib/less/environment/environment-api.js +25 -0
  16. package/lib/less/environment/environment.js +59 -0
  17. package/lib/less/environment/file-manager-api.js +103 -0
  18. package/lib/less/functions/boolean.js +13 -0
  19. package/lib/less/functions/color-blending.js +84 -0
  20. package/lib/less/functions/color.js +417 -0
  21. package/lib/less/functions/data-uri.js +74 -0
  22. package/lib/less/functions/default.js +25 -0
  23. package/lib/less/functions/function-caller.js +49 -0
  24. package/lib/less/functions/function-registry.js +35 -0
  25. package/lib/less/functions/index.js +33 -0
  26. package/lib/less/functions/list.js +143 -0
  27. package/lib/less/functions/math-helper.js +15 -0
  28. package/lib/less/functions/math.js +28 -0
  29. package/lib/less/functions/number.js +89 -0
  30. package/lib/less/functions/string.js +36 -0
  31. package/lib/less/functions/svg.js +87 -0
  32. package/lib/less/functions/types.js +70 -0
  33. package/lib/less/import-manager.js +169 -0
  34. package/lib/less/index.js +92 -0
  35. package/lib/less/less-error.js +140 -0
  36. package/lib/less/logger.js +34 -0
  37. package/lib/less/parse-tree.js +66 -0
  38. package/lib/less/parse.js +89 -0
  39. package/lib/less/parser/chunker.js +122 -0
  40. package/lib/less/parser/parser-input.js +390 -0
  41. package/lib/less/parser/parser.js +2418 -0
  42. package/lib/less/plugin-manager.js +168 -0
  43. package/lib/less/render.js +42 -0
  44. package/lib/less/source-map-builder.js +77 -0
  45. package/lib/less/source-map-output.js +149 -0
  46. package/lib/less/transform-tree.js +96 -0
  47. package/lib/less/tree/anonymous.js +37 -0
  48. package/lib/less/tree/assignment.js +33 -0
  49. package/lib/less/tree/atrule.js +165 -0
  50. package/lib/less/tree/attribute.js +34 -0
  51. package/lib/less/tree/call.js +105 -0
  52. package/lib/less/tree/color.js +246 -0
  53. package/lib/less/tree/combinator.js +29 -0
  54. package/lib/less/tree/comment.js +29 -0
  55. package/lib/less/tree/condition.js +43 -0
  56. package/lib/less/tree/debug-info.js +34 -0
  57. package/lib/less/tree/declaration.js +115 -0
  58. package/lib/less/tree/detached-ruleset.js +30 -0
  59. package/lib/less/tree/dimension.js +179 -0
  60. package/lib/less/tree/element.js +73 -0
  61. package/lib/less/tree/expression.js +74 -0
  62. package/lib/less/tree/extend.js +66 -0
  63. package/lib/less/tree/import.js +184 -0
  64. package/lib/less/tree/index.js +54 -0
  65. package/lib/less/tree/javascript.js +33 -0
  66. package/lib/less/tree/js-eval-node.js +58 -0
  67. package/lib/less/tree/keyword.js +21 -0
  68. package/lib/less/tree/media.js +154 -0
  69. package/lib/less/tree/mixin-call.js +215 -0
  70. package/lib/less/tree/mixin-definition.js +229 -0
  71. package/lib/less/tree/namespace-value.js +87 -0
  72. package/lib/less/tree/negative.js +26 -0
  73. package/lib/less/tree/node.js +178 -0
  74. package/lib/less/tree/operation.js +62 -0
  75. package/lib/less/tree/paren.js +22 -0
  76. package/lib/less/tree/property.js +77 -0
  77. package/lib/less/tree/quoted.js +70 -0
  78. package/lib/less/tree/ruleset.js +867 -0
  79. package/lib/less/tree/selector.js +146 -0
  80. package/lib/less/tree/unicode-descriptor.js +13 -0
  81. package/lib/less/tree/unit.js +141 -0
  82. package/lib/less/tree/url.js +65 -0
  83. package/lib/less/tree/value.js +44 -0
  84. package/lib/less/tree/variable-call.js +46 -0
  85. package/lib/less/tree/variable.js +67 -0
  86. package/lib/less/utils.js +122 -0
  87. package/lib/less/visitors/extend-visitor.js +505 -0
  88. package/lib/less/visitors/import-sequencer.js +58 -0
  89. package/lib/less/visitors/import-visitor.js +189 -0
  90. package/lib/less/visitors/index.js +15 -0
  91. package/lib/less/visitors/join-selector-visitor.js +57 -0
  92. package/lib/less/visitors/set-tree-visibility-visitor.js +45 -0
  93. package/lib/less/visitors/to-css-visitor.js +363 -0
  94. package/lib/less/visitors/visitor.js +163 -0
  95. package/lib/less-browser/add-default-options.js +49 -0
  96. package/lib/less-browser/bootstrap.js +69 -0
  97. package/lib/less-browser/browser.js +65 -0
  98. package/lib/less-browser/cache.js +43 -0
  99. package/lib/less-browser/error-reporting.js +170 -0
  100. package/lib/less-browser/file-manager.js +113 -0
  101. package/lib/less-browser/image-size.js +28 -0
  102. package/lib/less-browser/index.js +285 -0
  103. package/lib/less-browser/log-listener.js +42 -0
  104. package/lib/less-browser/plugin-loader.js +26 -0
  105. package/lib/less-browser/utils.js +24 -0
  106. package/lib/less-node/environment.js +16 -0
  107. package/lib/less-node/file-manager.js +177 -0
  108. package/lib/less-node/fs.js +10 -0
  109. package/lib/less-node/image-size.js +58 -0
  110. package/lib/less-node/index.js +27 -0
  111. package/lib/less-node/lessc-helper.js +89 -0
  112. package/lib/less-node/plugin-loader.js +53 -0
  113. package/lib/less-node/url-file-manager.js +49 -0
  114. package/lib/lessc.js +557 -0
  115. package/lib/source-map/source-map-0.1.31.js +1933 -0
  116. package/lib/source-map/source-map-footer.js +4 -0
  117. package/lib/source-map/source-map-header.js +3 -0
  118. package/package.json +1 -1
  119. package/test/.DS_Store +0 -0
  120. package/test/browser/less.min.js +11 -0
  121. package/test/browser/less.min.js.map +1 -0
  122. package/test/css/css-escapes.css +1 -0
  123. package/test/less/css-escapes.less +3 -1
  124. package/.git/index +0 -0
@@ -0,0 +1,146 @@
1
+ import Node from './node';
2
+ import Element from './element';
3
+ import LessError from '../less-error';
4
+
5
+ class Selector extends Node {
6
+ constructor(elements, extendList, condition, index, currentFileInfo, visibilityInfo) {
7
+ super();
8
+
9
+ this.extendList = extendList;
10
+ this.condition = condition;
11
+ this.evaldCondition = !condition;
12
+ this._index = index;
13
+ this._fileInfo = currentFileInfo;
14
+ this.elements = this.getElements(elements);
15
+ this.mixinElements_ = undefined;
16
+ this.copyVisibilityInfo(visibilityInfo);
17
+ this.setParent(this.elements, this);
18
+ }
19
+
20
+ accept(visitor) {
21
+ if (this.elements) {
22
+ this.elements = visitor.visitArray(this.elements);
23
+ }
24
+ if (this.extendList) {
25
+ this.extendList = visitor.visitArray(this.extendList);
26
+ }
27
+ if (this.condition) {
28
+ this.condition = visitor.visit(this.condition);
29
+ }
30
+ }
31
+
32
+ createDerived(elements, extendList, evaldCondition) {
33
+ elements = this.getElements(elements);
34
+ const newSelector = new Selector(elements, extendList || this.extendList,
35
+ null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
36
+ newSelector.evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition;
37
+ newSelector.mediaEmpty = this.mediaEmpty;
38
+ return newSelector;
39
+ }
40
+
41
+ getElements(els) {
42
+ if (!els) {
43
+ return [new Element('', '&', false, this._index, this._fileInfo)];
44
+ }
45
+ if (typeof els === 'string') {
46
+ this.parse.parseNode(
47
+ els,
48
+ ['selector'],
49
+ this._index,
50
+ this._fileInfo,
51
+ function(err, result) {
52
+ if (err) {
53
+ throw new LessError({
54
+ index: err.index,
55
+ message: err.message
56
+ }, this.parse.imports, this._fileInfo.filename);
57
+ }
58
+ els = result[0].elements;
59
+ });
60
+ }
61
+ return els;
62
+ }
63
+
64
+ createEmptySelectors() {
65
+ const el = new Element('', '&', false, this._index, this._fileInfo);
66
+ const sels = [new Selector([el], null, null, this._index, this._fileInfo)];
67
+ sels[0].mediaEmpty = true;
68
+ return sels;
69
+ }
70
+
71
+ match(other) {
72
+ const elements = this.elements;
73
+ const len = elements.length;
74
+ let olen;
75
+ let i;
76
+
77
+ other = other.mixinElements();
78
+ olen = other.length;
79
+ if (olen === 0 || len < olen) {
80
+ return 0;
81
+ } else {
82
+ for (i = 0; i < olen; i++) {
83
+ if (elements[i].value !== other[i]) {
84
+ return 0;
85
+ }
86
+ }
87
+ }
88
+
89
+ return olen; // return number of matched elements
90
+ }
91
+
92
+ mixinElements() {
93
+ if (this.mixinElements_) {
94
+ return this.mixinElements_;
95
+ }
96
+
97
+ let elements = this.elements.map( v => v.combinator.value + (v.value.value || v.value)).join('').match(/[,&#\*\.\w-]([\w-]|(\\.))*/g);
98
+
99
+ if (elements) {
100
+ if (elements[0] === '&') {
101
+ elements.shift();
102
+ }
103
+ } else {
104
+ elements = [];
105
+ }
106
+
107
+ return (this.mixinElements_ = elements);
108
+ }
109
+
110
+ isJustParentSelector() {
111
+ return !this.mediaEmpty &&
112
+ this.elements.length === 1 &&
113
+ this.elements[0].value === '&' &&
114
+ (this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
115
+ }
116
+
117
+ eval(context) {
118
+ const evaldCondition = this.condition && this.condition.eval(context);
119
+ let elements = this.elements;
120
+ let extendList = this.extendList;
121
+
122
+ elements = elements && elements.map(e => e.eval(context));
123
+ extendList = extendList && extendList.map(extend => extend.eval(context));
124
+
125
+ return this.createDerived(elements, extendList, evaldCondition);
126
+ }
127
+
128
+ genCSS(context, output) {
129
+ let i;
130
+ let element;
131
+ if ((!context || !context.firstSelector) && this.elements[0].combinator.value === '') {
132
+ output.add(' ', this.fileInfo(), this.getIndex());
133
+ }
134
+ for (i = 0; i < this.elements.length; i++) {
135
+ element = this.elements[i];
136
+ element.genCSS(context, output);
137
+ }
138
+ }
139
+
140
+ getIsOutput() {
141
+ return this.evaldCondition;
142
+ }
143
+ }
144
+
145
+ Selector.prototype.type = 'Selector';
146
+ export default Selector;
@@ -0,0 +1,13 @@
1
+ import Node from './node';
2
+
3
+ class UnicodeDescriptor extends Node {
4
+ constructor(value) {
5
+ super();
6
+
7
+ this.value = value;
8
+ }
9
+ }
10
+
11
+ UnicodeDescriptor.prototype.type = 'UnicodeDescriptor';
12
+
13
+ export default UnicodeDescriptor;
@@ -0,0 +1,141 @@
1
+ import Node from './node';
2
+ import unitConversions from '../data/unit-conversions';
3
+ import * as utils from '../utils';
4
+
5
+ class Unit extends Node {
6
+ constructor(numerator, denominator, backupUnit) {
7
+ super();
8
+
9
+ this.numerator = numerator ? utils.copyArray(numerator).sort() : [];
10
+ this.denominator = denominator ? utils.copyArray(denominator).sort() : [];
11
+ if (backupUnit) {
12
+ this.backupUnit = backupUnit;
13
+ } else if (numerator && numerator.length) {
14
+ this.backupUnit = numerator[0];
15
+ }
16
+ }
17
+
18
+ clone() {
19
+ return new Unit(utils.copyArray(this.numerator), utils.copyArray(this.denominator), this.backupUnit);
20
+ }
21
+
22
+ genCSS(context, output) {
23
+ // Dimension checks the unit is singular and throws an error if in strict math mode.
24
+ const strictUnits = context && context.strictUnits;
25
+ if (this.numerator.length === 1) {
26
+ output.add(this.numerator[0]); // the ideal situation
27
+ } else if (!strictUnits && this.backupUnit) {
28
+ output.add(this.backupUnit);
29
+ } else if (!strictUnits && this.denominator.length) {
30
+ output.add(this.denominator[0]);
31
+ }
32
+ }
33
+
34
+ toString() {
35
+ let i;
36
+ let returnStr = this.numerator.join('*');
37
+ for (i = 0; i < this.denominator.length; i++) {
38
+ returnStr += `/${this.denominator[i]}`;
39
+ }
40
+ return returnStr;
41
+ }
42
+
43
+ compare(other) {
44
+ return this.is(other.toString()) ? 0 : undefined;
45
+ }
46
+
47
+ is(unitString) {
48
+ return this.toString().toUpperCase() === unitString.toUpperCase();
49
+ }
50
+
51
+ isLength() {
52
+ return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS());
53
+ }
54
+
55
+ isEmpty() {
56
+ return this.numerator.length === 0 && this.denominator.length === 0;
57
+ }
58
+
59
+ isSingular() {
60
+ return this.numerator.length <= 1 && this.denominator.length === 0;
61
+ }
62
+
63
+ map(callback) {
64
+ let i;
65
+
66
+ for (i = 0; i < this.numerator.length; i++) {
67
+ this.numerator[i] = callback(this.numerator[i], false);
68
+ }
69
+
70
+ for (i = 0; i < this.denominator.length; i++) {
71
+ this.denominator[i] = callback(this.denominator[i], true);
72
+ }
73
+ }
74
+
75
+ usedUnits() {
76
+ let group;
77
+ const result = {};
78
+ let mapUnit;
79
+ let groupName;
80
+
81
+ mapUnit = atomicUnit => {
82
+ /* jshint loopfunc:true */
83
+ if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
84
+ result[groupName] = atomicUnit;
85
+ }
86
+
87
+ return atomicUnit;
88
+ };
89
+
90
+ for (groupName in unitConversions) {
91
+ if (unitConversions.hasOwnProperty(groupName)) {
92
+ group = unitConversions[groupName];
93
+
94
+ this.map(mapUnit);
95
+ }
96
+ }
97
+
98
+ return result;
99
+ }
100
+
101
+ cancel() {
102
+ const counter = {};
103
+ let atomicUnit;
104
+ let i;
105
+
106
+ for (i = 0; i < this.numerator.length; i++) {
107
+ atomicUnit = this.numerator[i];
108
+ counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
109
+ }
110
+
111
+ for (i = 0; i < this.denominator.length; i++) {
112
+ atomicUnit = this.denominator[i];
113
+ counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
114
+ }
115
+
116
+ this.numerator = [];
117
+ this.denominator = [];
118
+
119
+ for (atomicUnit in counter) {
120
+ if (counter.hasOwnProperty(atomicUnit)) {
121
+ const count = counter[atomicUnit];
122
+
123
+ if (count > 0) {
124
+ for (i = 0; i < count; i++) {
125
+ this.numerator.push(atomicUnit);
126
+ }
127
+ } else if (count < 0) {
128
+ for (i = 0; i < -count; i++) {
129
+ this.denominator.push(atomicUnit);
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ this.numerator.sort();
136
+ this.denominator.sort();
137
+ }
138
+ }
139
+
140
+ Unit.prototype.type = 'Unit';
141
+ export default Unit;
@@ -0,0 +1,65 @@
1
+ import Node from './node';
2
+
3
+ class URL extends Node {
4
+ constructor(val, index, currentFileInfo, isEvald) {
5
+ super();
6
+
7
+ this.value = val;
8
+ this._index = index;
9
+ this._fileInfo = currentFileInfo;
10
+ this.isEvald = isEvald;
11
+ }
12
+
13
+ accept(visitor) {
14
+ this.value = visitor.visit(this.value);
15
+ }
16
+
17
+ genCSS(context, output) {
18
+ output.add('url(');
19
+ this.value.genCSS(context, output);
20
+ output.add(')');
21
+ }
22
+
23
+ eval(context) {
24
+ const val = this.value.eval(context);
25
+ let rootpath;
26
+
27
+ if (!this.isEvald) {
28
+ // Add the rootpath if the URL requires a rewrite
29
+ rootpath = this.fileInfo() && this.fileInfo().rootpath;
30
+ if (typeof rootpath === 'string' &&
31
+ typeof val.value === 'string' &&
32
+ context.pathRequiresRewrite(val.value)) {
33
+ if (!val.quote) {
34
+ rootpath = escapePath(rootpath);
35
+ }
36
+ val.value = context.rewritePath(val.value, rootpath);
37
+ } else {
38
+ val.value = context.normalizePath(val.value);
39
+ }
40
+
41
+ // Add url args if enabled
42
+ if (context.urlArgs) {
43
+ if (!val.value.match(/^\s*data:/)) {
44
+ const delimiter = val.value.indexOf('?') === -1 ? '?' : '&';
45
+ const urlArgs = delimiter + context.urlArgs;
46
+ if (val.value.indexOf('#') !== -1) {
47
+ val.value = val.value.replace('#', `${urlArgs}#`);
48
+ } else {
49
+ val.value += urlArgs;
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ return new URL(val, this.getIndex(), this.fileInfo(), true);
56
+ }
57
+ }
58
+
59
+ URL.prototype.type = 'Url';
60
+
61
+ function escapePath(path) {
62
+ return path.replace(/[\(\)'"\s]/g, match => `\\${match}`);
63
+ }
64
+
65
+ export default URL;
@@ -0,0 +1,44 @@
1
+ import Node from './node';
2
+
3
+ class Value extends Node {
4
+ constructor(value) {
5
+ super();
6
+
7
+ if (!value) {
8
+ throw new Error('Value requires an array argument');
9
+ }
10
+ if (!Array.isArray(value)) {
11
+ this.value = [ value ];
12
+ }
13
+ else {
14
+ this.value = value;
15
+ }
16
+ }
17
+
18
+ accept(visitor) {
19
+ if (this.value) {
20
+ this.value = visitor.visitArray(this.value);
21
+ }
22
+ }
23
+
24
+ eval(context) {
25
+ if (this.value.length === 1) {
26
+ return this.value[0].eval(context);
27
+ } else {
28
+ return new Value(this.value.map(v => v.eval(context)));
29
+ }
30
+ }
31
+
32
+ genCSS(context, output) {
33
+ let i;
34
+ for (i = 0; i < this.value.length; i++) {
35
+ this.value[i].genCSS(context, output);
36
+ if (i + 1 < this.value.length) {
37
+ output.add((context && context.compress) ? ',' : ', ');
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ Value.prototype.type = 'Value';
44
+ export default Value;
@@ -0,0 +1,46 @@
1
+ import Node from './node';
2
+ import Variable from './variable';
3
+ import Ruleset from './ruleset';
4
+ import DetachedRuleset from './detached-ruleset';
5
+ import LessError from '../less-error';
6
+
7
+ class VariableCall extends Node {
8
+ constructor(variable, index, currentFileInfo) {
9
+ super();
10
+
11
+ this.variable = variable;
12
+ this._index = index;
13
+ this._fileInfo = currentFileInfo;
14
+ this.allowRoot = true;
15
+ }
16
+
17
+ eval(context) {
18
+ let rules;
19
+ let detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context);
20
+ const error = new LessError({message: `Could not evaluate variable call ${this.variable}`});
21
+
22
+ if (!detachedRuleset.ruleset) {
23
+ if (detachedRuleset.rules) {
24
+ rules = detachedRuleset;
25
+ }
26
+ else if (Array.isArray(detachedRuleset)) {
27
+ rules = new Ruleset('', detachedRuleset);
28
+ }
29
+ else if (Array.isArray(detachedRuleset.value)) {
30
+ rules = new Ruleset('', detachedRuleset.value);
31
+ }
32
+ else {
33
+ throw error;
34
+ }
35
+ detachedRuleset = new DetachedRuleset(rules);
36
+ }
37
+
38
+ if (detachedRuleset.ruleset) {
39
+ return detachedRuleset.callEval(context);
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+
45
+ VariableCall.prototype.type = 'VariableCall';
46
+ export default VariableCall;
@@ -0,0 +1,67 @@
1
+ import Node from './node';
2
+ import Call from './call';
3
+
4
+ class Variable extends Node {
5
+ constructor(name, index, currentFileInfo) {
6
+ super();
7
+
8
+ this.name = name;
9
+ this._index = index;
10
+ this._fileInfo = currentFileInfo;
11
+ }
12
+
13
+ eval(context) {
14
+ let variable;
15
+ let name = this.name;
16
+
17
+ if (name.indexOf('@@') === 0) {
18
+ name = `@${new Variable(name.slice(1), this.getIndex(), this.fileInfo()).eval(context).value}`;
19
+ }
20
+
21
+ if (this.evaluating) {
22
+ throw { type: 'Name',
23
+ message: `Recursive variable definition for ${name}`,
24
+ filename: this.fileInfo().filename,
25
+ index: this.getIndex() };
26
+ }
27
+
28
+ this.evaluating = true;
29
+
30
+ variable = this.find(context.frames, frame => {
31
+ const v = frame.variable(name);
32
+ if (v) {
33
+ if (v.important) {
34
+ const importantScope = context.importantScope[context.importantScope.length - 1];
35
+ importantScope.important = v.important;
36
+ }
37
+ // If in calc, wrap vars in a function call to cascade evaluate args first
38
+ if (context.inCalc) {
39
+ return (new Call('_SELF', [v.value])).eval(context);
40
+ }
41
+ else {
42
+ return v.value.eval(context);
43
+ }
44
+ }
45
+ });
46
+ if (variable) {
47
+ this.evaluating = false;
48
+ return variable;
49
+ } else {
50
+ throw { type: 'Name',
51
+ message: `variable ${name} is undefined`,
52
+ filename: this.fileInfo().filename,
53
+ index: this.getIndex() };
54
+ }
55
+ }
56
+
57
+ find(obj, fun) {
58
+ for (let i = 0, r; i < obj.length; i++) {
59
+ r = fun.call(obj, obj[i]);
60
+ if (r) { return r; }
61
+ }
62
+ return null;
63
+ }
64
+ }
65
+
66
+ Variable.prototype.type = 'Variable';
67
+ export default Variable;
@@ -0,0 +1,122 @@
1
+ /* jshint proto: true */
2
+ import * as Constants from './constants';
3
+ import CloneHelper from 'clone';
4
+
5
+ export function getLocation(index, inputStream) {
6
+ let n = index + 1;
7
+ let line = null;
8
+ let column = -1;
9
+
10
+ while (--n >= 0 && inputStream.charAt(n) !== '\n') {
11
+ column++;
12
+ }
13
+
14
+ if (typeof index === 'number') {
15
+ line = (inputStream.slice(0, index).match(/\n/g) || '').length;
16
+ }
17
+
18
+ return {
19
+ line,
20
+ column
21
+ };
22
+ }
23
+
24
+ export function copyArray(arr) {
25
+ let i;
26
+ const length = arr.length;
27
+ const copy = new Array(length);
28
+
29
+ for (i = 0; i < length; i++) {
30
+ copy[i] = arr[i];
31
+ }
32
+ return copy;
33
+ }
34
+
35
+ export function clone(obj) {
36
+ const cloned = {};
37
+ for (const prop in obj) {
38
+ if (obj.hasOwnProperty(prop)) {
39
+ cloned[prop] = obj[prop];
40
+ }
41
+ }
42
+ return cloned;
43
+ }
44
+
45
+ export function defaults(obj1, obj2) {
46
+ let newObj = obj2 || {};
47
+ if (!obj2._defaults) {
48
+ newObj = {};
49
+ const defaults = CloneHelper(obj1);
50
+ newObj._defaults = defaults;
51
+ const cloned = obj2 ? CloneHelper(obj2) : {};
52
+ Object.assign(newObj, defaults, cloned);
53
+ }
54
+ return newObj;
55
+ }
56
+
57
+ export function copyOptions(obj1, obj2) {
58
+ if (obj2 && obj2._defaults) {
59
+ return obj2;
60
+ }
61
+ const opts = defaults(obj1, obj2);
62
+ if (opts.strictMath) {
63
+ opts.math = Constants.Math.STRICT_LEGACY;
64
+ }
65
+ // Back compat with changed relativeUrls option
66
+ if (opts.relativeUrls) {
67
+ opts.rewriteUrls = Constants.RewriteUrls.ALL;
68
+ }
69
+ if (typeof opts.math === 'string') {
70
+ switch (opts.math.toLowerCase()) {
71
+ case 'always':
72
+ opts.math = Constants.Math.ALWAYS;
73
+ break;
74
+ case 'parens-division':
75
+ opts.math = Constants.Math.PARENS_DIVISION;
76
+ break;
77
+ case 'strict':
78
+ case 'parens':
79
+ opts.math = Constants.Math.PARENS;
80
+ break;
81
+ case 'strict-legacy':
82
+ opts.math = Constants.Math.STRICT_LEGACY;
83
+ }
84
+ }
85
+ if (typeof opts.rewriteUrls === 'string') {
86
+ switch (opts.rewriteUrls.toLowerCase()) {
87
+ case 'off':
88
+ opts.rewriteUrls = Constants.RewriteUrls.OFF;
89
+ break;
90
+ case 'local':
91
+ opts.rewriteUrls = Constants.RewriteUrls.LOCAL;
92
+ break;
93
+ case 'all':
94
+ opts.rewriteUrls = Constants.RewriteUrls.ALL;
95
+ break;
96
+ }
97
+ }
98
+ return opts;
99
+ }
100
+
101
+ export function merge(obj1, obj2) {
102
+ for (const prop in obj2) {
103
+ if (obj2.hasOwnProperty(prop)) {
104
+ obj1[prop] = obj2[prop];
105
+ }
106
+ }
107
+ return obj1;
108
+ }
109
+
110
+ export function flattenArray(arr, result = []) {
111
+ for (let i = 0, length = arr.length; i < length; i++) {
112
+ const value = arr[i];
113
+ if (Array.isArray(value)) {
114
+ flattenArray(value, result);
115
+ } else {
116
+ if (value !== undefined) {
117
+ result.push(value);
118
+ }
119
+ }
120
+ }
121
+ return result;
122
+ }