mambascript 0.5.4 → 2.0.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.
- package/CHANGELOG.md +326 -0
- package/README.md +509 -267
- package/bin/mamba +1 -258
- package/decision.js +1 -246
- package/docs/coverage.md +70 -0
- package/docs/features.md +3348 -0
- package/docs/perf.md +94 -0
- package/docs/reference.md +1295 -0
- package/docs/vs-coffeescript.md +1593 -0
- package/docs/vs-iced-coffeescript.md +626 -0
- package/docs/vs-typescript.md +107 -0
- package/esm.js +8 -0
- package/jest.js +33 -0
- package/lib/black.js +17 -13
- package/lib/browser.js +2 -4
- package/lib/cli.js +207 -136
- package/lib/compiler.js +1162 -93
- package/lib/decision.js +10 -10
- package/lib/diagnostics.js +219 -0
- package/lib/esm-hooks.js +60 -0
- package/lib/fast-parser.js +3469 -0
- package/lib/functional-helpers.js +26 -9
- package/lib/helpers.js +67 -50
- package/lib/js-nodes.js +151 -12
- package/lib/lexer.js +1499 -0
- package/lib/light-module.js +200 -63
- package/lib/mamba.js +372 -0
- package/lib/module.js +23 -172
- package/lib/nodes.js +84 -21
- package/lib/optimiser.js +29 -9
- package/lib/optparse.js +32 -15
- package/lib/parser.js +9433 -4840
- package/lib/preprocessor.js +3 -5
- package/lib/register.js +49 -56
- package/lib/repl.js +28 -9
- package/lib/reporter.js +106 -69
- package/lib/run.js +3 -5
- package/lib/string-scanner.js +94 -0
- package/lib/syntax-tables.js +480 -0
- package/lib/type-checker.js +258 -44
- package/lib/type-helpers.js +28 -10
- package/lib/type-resolver.js +256 -34
- package/lib/type-scope.js +10 -6
- package/lib/type-walker.js +664 -85
- package/lib/types.js +17 -7
- package/lib/underscore.js +170 -76
- package/lib/unicode-classes.js +122 -0
- package/mambaview.js +1 -0
- package/package.json +49 -46
- package/stdlib.js +1 -0
- package/vendor/README.md +40 -0
- package/vendor/escodegen/LICENSE.BSD +19 -0
- package/vendor/escodegen/escodegen.js +2289 -0
- package/vendor/estraverse/LICENSE.BSD +19 -0
- package/vendor/estraverse/estraverse.js +706 -0
- package/vendor/mambacodegen/LICENSE +24 -0
- package/vendor/mambacodegen/lib/mscodegen.js +620 -0
- package/vendor/patches/escodegen.diff +130 -0
- package/vendor/patches/estraverse.diff +51 -0
- package/vendor/patches/pegjs.diff +70 -0
- package/vendor/patches/source-map.diff +160 -0
- package/vendor/source-map/LICENSE +28 -0
- package/vendor/source-map/lib/source-map/array-set.js +92 -0
- package/vendor/source-map/lib/source-map/base64-vlq.js +140 -0
- package/vendor/source-map/lib/source-map/base64.js +38 -0
- package/vendor/source-map/lib/source-map/binary-search.js +77 -0
- package/vendor/source-map/lib/source-map/source-map-consumer.js +404 -0
- package/vendor/source-map/lib/source-map/source-map-generator.js +229 -0
- package/vendor/source-map/lib/source-map/source-node.js +201 -0
- package/vendor/source-map/lib/source-map/util.js +57 -0
- package/vendor/source-map/lib/source-map.js +8 -0
- package/bin/fix +0 -17
- package/bin/updateImports +0 -46
- package/build.js +0 -25
- package/lib/module-esm.js +0 -901
- package/lib/pegjs-kofu-plugin.js +0 -35
- package/lib/pegjs-mamba-plugin.js +0 -35
- package/lib/processor-esm.js +0 -507
- package/mamba +0 -259
- package/msast.js +0 -1
- package/utils/gulp-mamba.js +0 -29
- /package/{lib/esm.js → vendor/patches/mambacodegen.diff} +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
|
4
|
+
* Licensed under the New BSD license. See LICENSE or:
|
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
// Vendored into MambaScript from source-map 0.1.11 (BSD-3-Clause, see ../../LICENSE); amdefine wrapper removed.
|
|
8
|
+
|
|
9
|
+
var base64VLQ = require('./base64-vlq');
|
|
10
|
+
var util = require('./util');
|
|
11
|
+
var ArraySet = require('./array-set').ArraySet;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An instance of the SourceMapGenerator represents a source map which is
|
|
15
|
+
* being built incrementally. To create a new one, you must pass an object
|
|
16
|
+
* with the following properties:
|
|
17
|
+
*
|
|
18
|
+
* - file: The filename of the generated source.
|
|
19
|
+
* - sourceRoot: An optional root for all URLs in this source map.
|
|
20
|
+
*/
|
|
21
|
+
function SourceMapGenerator(aArgs) {
|
|
22
|
+
this._file = util.getArg(aArgs, 'file');
|
|
23
|
+
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
|
|
24
|
+
this._sources = new ArraySet();
|
|
25
|
+
this._names = new ArraySet();
|
|
26
|
+
this._mappings = [];
|
|
27
|
+
this._sourcesContents = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
SourceMapGenerator.prototype._version = 3;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Add a single mapping from original source line and column to the generated
|
|
34
|
+
* source's line and column for this source map being created. The mapping
|
|
35
|
+
* object should have the following properties:
|
|
36
|
+
*
|
|
37
|
+
* - generated: An object with the generated line and column positions.
|
|
38
|
+
* - original: An object with the original line and column positions.
|
|
39
|
+
* - source: The original source file (relative to the sourceRoot).
|
|
40
|
+
* - name: An optional original token name for this mapping.
|
|
41
|
+
*/
|
|
42
|
+
SourceMapGenerator.prototype.addMapping =
|
|
43
|
+
function SourceMapGenerator_addMapping(aArgs) {
|
|
44
|
+
var generated = util.getArg(aArgs, 'generated');
|
|
45
|
+
var original = util.getArg(aArgs, 'original', null);
|
|
46
|
+
var source = util.getArg(aArgs, 'source', null);
|
|
47
|
+
var name = util.getArg(aArgs, 'name', null);
|
|
48
|
+
|
|
49
|
+
this._validateMapping(generated, original, source, name);
|
|
50
|
+
|
|
51
|
+
if (source && !this._sources.has(source)) {
|
|
52
|
+
this._sources.add(source);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (name && !this._names.has(name)) {
|
|
56
|
+
this._names.add(name);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this._mappings.push({
|
|
60
|
+
generated: generated,
|
|
61
|
+
original: original,
|
|
62
|
+
source: source,
|
|
63
|
+
name: name
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Set the source content for a source file.
|
|
69
|
+
*/
|
|
70
|
+
SourceMapGenerator.prototype.setSourceContent =
|
|
71
|
+
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
|
|
72
|
+
if(aSourceContent !== null) {
|
|
73
|
+
// Add the source content to the _sourcesContents map.
|
|
74
|
+
// Create a new _sourcesContents map if the property is null.
|
|
75
|
+
if(!this._sourcesContents) {
|
|
76
|
+
this._sourcesContents = {};
|
|
77
|
+
}
|
|
78
|
+
this._sourcesContents[util.toSetString(aSourceFile)] = aSourceContent;
|
|
79
|
+
} else {
|
|
80
|
+
// Remove the source file from the _sourcesContents map.
|
|
81
|
+
// If the _sourcesContents map is empty, set the property to null.
|
|
82
|
+
delete this._sourcesContents[util.toSetString(aSourceFile)];
|
|
83
|
+
if(Object.keys(this._sourcesContents).length === 0) {
|
|
84
|
+
this._sourcesContents = null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A mapping can have one of the three levels of data:
|
|
91
|
+
*
|
|
92
|
+
* 1. Just the generated position.
|
|
93
|
+
* 2. The Generated position, original position, and original source.
|
|
94
|
+
* 3. Generated and original position, original source, as well as a name
|
|
95
|
+
* token.
|
|
96
|
+
*
|
|
97
|
+
* To maintain consistency, we validate that any new mapping being added falls
|
|
98
|
+
* in to one of these categories.
|
|
99
|
+
*/
|
|
100
|
+
SourceMapGenerator.prototype._validateMapping =
|
|
101
|
+
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
|
|
102
|
+
aName) {
|
|
103
|
+
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
|
104
|
+
&& aGenerated.line > 0 && aGenerated.column >= 0
|
|
105
|
+
&& !aOriginal && !aSource && !aName) {
|
|
106
|
+
// Case 1.
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
|
110
|
+
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal
|
|
111
|
+
&& aGenerated.line > 0 && aGenerated.column >= 0
|
|
112
|
+
&& aOriginal.line > 0 && aOriginal.column >= 0
|
|
113
|
+
&& aSource) {
|
|
114
|
+
// Cases 2 and 3.
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw new Error('Invalid mapping.');
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Serialize the accumulated mappings in to the stream of base 64 VLQs
|
|
124
|
+
* specified by the source map format.
|
|
125
|
+
*/
|
|
126
|
+
SourceMapGenerator.prototype._serializeMappings =
|
|
127
|
+
function SourceMapGenerator_serializeMappings() {
|
|
128
|
+
var previousGeneratedColumn = 0;
|
|
129
|
+
var previousGeneratedLine = 1;
|
|
130
|
+
var previousOriginalColumn = 0;
|
|
131
|
+
var previousOriginalLine = 0;
|
|
132
|
+
var previousName = 0;
|
|
133
|
+
var previousSource = 0;
|
|
134
|
+
var result = '';
|
|
135
|
+
var mapping;
|
|
136
|
+
|
|
137
|
+
// The mappings must be guarenteed to be in sorted order before we start
|
|
138
|
+
// serializing them or else the generated line numbers (which are defined
|
|
139
|
+
// via the ';' separators) will be all messed up. Note: it might be more
|
|
140
|
+
// performant to maintain the sorting as we insert them, rather than as we
|
|
141
|
+
// serialize them, but the big O is the same either way.
|
|
142
|
+
this._mappings.sort(function (mappingA, mappingB) {
|
|
143
|
+
var cmp = mappingA.generated.line - mappingB.generated.line;
|
|
144
|
+
return cmp === 0
|
|
145
|
+
? mappingA.generated.column - mappingB.generated.column
|
|
146
|
+
: cmp;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
for (var i = 0, len = this._mappings.length; i < len; i++) {
|
|
150
|
+
mapping = this._mappings[i];
|
|
151
|
+
|
|
152
|
+
if (mapping.generated.line !== previousGeneratedLine) {
|
|
153
|
+
previousGeneratedColumn = 0;
|
|
154
|
+
while (mapping.generated.line !== previousGeneratedLine) {
|
|
155
|
+
result += ';';
|
|
156
|
+
previousGeneratedLine++;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (i > 0) {
|
|
161
|
+
result += ',';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
result += base64VLQ.encode(mapping.generated.column
|
|
166
|
+
- previousGeneratedColumn);
|
|
167
|
+
previousGeneratedColumn = mapping.generated.column;
|
|
168
|
+
|
|
169
|
+
if (mapping.source && mapping.original) {
|
|
170
|
+
result += base64VLQ.encode(this._sources.indexOf(mapping.source)
|
|
171
|
+
- previousSource);
|
|
172
|
+
previousSource = this._sources.indexOf(mapping.source);
|
|
173
|
+
|
|
174
|
+
// lines are stored 0-based in SourceMap spec version 3
|
|
175
|
+
result += base64VLQ.encode(mapping.original.line - 1
|
|
176
|
+
- previousOriginalLine);
|
|
177
|
+
previousOriginalLine = mapping.original.line - 1;
|
|
178
|
+
|
|
179
|
+
result += base64VLQ.encode(mapping.original.column
|
|
180
|
+
- previousOriginalColumn);
|
|
181
|
+
previousOriginalColumn = mapping.original.column;
|
|
182
|
+
|
|
183
|
+
if (mapping.name) {
|
|
184
|
+
result += base64VLQ.encode(this._names.indexOf(mapping.name)
|
|
185
|
+
- previousName);
|
|
186
|
+
previousName = this._names.indexOf(mapping.name);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return result;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Externalize the source map.
|
|
196
|
+
*/
|
|
197
|
+
SourceMapGenerator.prototype.toJSON =
|
|
198
|
+
function SourceMapGenerator_toJSON() {
|
|
199
|
+
var map = {
|
|
200
|
+
version: this._version,
|
|
201
|
+
file: this._file,
|
|
202
|
+
sources: this._sources.toArray(),
|
|
203
|
+
names: this._names.toArray(),
|
|
204
|
+
mappings: this._serializeMappings()
|
|
205
|
+
};
|
|
206
|
+
if (this._sourceRoot) {
|
|
207
|
+
map.sourceRoot = this._sourceRoot;
|
|
208
|
+
}
|
|
209
|
+
if (this._sourcesContents) {
|
|
210
|
+
map.sourcesContent = map.sources.map(function(source) {
|
|
211
|
+
return Object.prototype.hasOwnProperty.call(
|
|
212
|
+
this._sourcesContents, util.toSetString(source))
|
|
213
|
+
? this._sourcesContents[util.toSetString(source)]
|
|
214
|
+
: null;
|
|
215
|
+
}, this);
|
|
216
|
+
}
|
|
217
|
+
return map;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Render the source map being generated to a string.
|
|
222
|
+
*/
|
|
223
|
+
SourceMapGenerator.prototype.toString =
|
|
224
|
+
function SourceMapGenerator_toString() {
|
|
225
|
+
return JSON.stringify(this);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
exports.SourceMapGenerator = SourceMapGenerator;
|
|
229
|
+
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
|
4
|
+
* Licensed under the New BSD license. See LICENSE or:
|
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
// Vendored into MambaScript from source-map 0.1.11 (BSD-3-Clause, see ../../LICENSE); amdefine wrapper removed.
|
|
8
|
+
|
|
9
|
+
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SourceNodes provide a way to abstract over interpolating/concatenating
|
|
13
|
+
* snippets of generated JavaScript source code while maintaining the line and
|
|
14
|
+
* column information associated with the original source code.
|
|
15
|
+
*
|
|
16
|
+
* @param aLine The original line number.
|
|
17
|
+
* @param aColumn The original column number.
|
|
18
|
+
* @param aSource The original source's filename.
|
|
19
|
+
* @param aChunks Optional. An array of strings which are snippets of
|
|
20
|
+
* generated JS, or other SourceNodes.
|
|
21
|
+
* @param aName The original identifier.
|
|
22
|
+
*/
|
|
23
|
+
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
|
24
|
+
this.children = [];
|
|
25
|
+
this.line = aLine === undefined ? null : aLine;
|
|
26
|
+
this.column = aColumn === undefined ? null : aColumn;
|
|
27
|
+
this.source = aSource === undefined ? null : aSource;
|
|
28
|
+
this.name = aName === undefined ? null : aName;
|
|
29
|
+
if (aChunks != null) this.add(aChunks);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Add a chunk of generated JS to this source node.
|
|
34
|
+
*
|
|
35
|
+
* @param aChunk A string snippet of generated JS code, another instance of
|
|
36
|
+
* SourceNode, or an array where each member is one of those things.
|
|
37
|
+
*/
|
|
38
|
+
SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
|
39
|
+
if (Array.isArray(aChunk)) {
|
|
40
|
+
aChunk.forEach(function (chunk) {
|
|
41
|
+
this.add(chunk);
|
|
42
|
+
}, this);
|
|
43
|
+
}
|
|
44
|
+
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
|
45
|
+
if (aChunk) {
|
|
46
|
+
this.children.push(aChunk);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new TypeError(
|
|
51
|
+
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Add a chunk of generated JS to the beginning of this source node.
|
|
59
|
+
*
|
|
60
|
+
* @param aChunk A string snippet of generated JS code, another instance of
|
|
61
|
+
* SourceNode, or an array where each member is one of those things.
|
|
62
|
+
*/
|
|
63
|
+
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
|
64
|
+
if (Array.isArray(aChunk)) {
|
|
65
|
+
for (var i = aChunk.length-1; i >= 0; i--) {
|
|
66
|
+
this.prepend(aChunk[i]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
|
70
|
+
this.children.unshift(aChunk);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new TypeError(
|
|
74
|
+
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Walk over the tree of JS snippets in this node and its children. The
|
|
82
|
+
* walking function is called once for each snippet of JS and is passed that
|
|
83
|
+
* snippet and the its original associated source's line/column location.
|
|
84
|
+
*
|
|
85
|
+
* @param aFn The traversal function.
|
|
86
|
+
*/
|
|
87
|
+
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
|
88
|
+
this.children.forEach(function (chunk) {
|
|
89
|
+
if (chunk instanceof SourceNode) {
|
|
90
|
+
chunk.walk(aFn);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (chunk !== '') {
|
|
94
|
+
aFn(chunk, { source: this.source,
|
|
95
|
+
line: this.line,
|
|
96
|
+
column: this.column,
|
|
97
|
+
name: this.name });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, this);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
|
|
105
|
+
* each of `this.children`.
|
|
106
|
+
*
|
|
107
|
+
* @param aSep The separator.
|
|
108
|
+
*/
|
|
109
|
+
SourceNode.prototype.join = function SourceNode_join(aSep) {
|
|
110
|
+
var newChildren;
|
|
111
|
+
var i;
|
|
112
|
+
var len = this.children.length
|
|
113
|
+
if (len > 0) {
|
|
114
|
+
newChildren = [];
|
|
115
|
+
for (i = 0; i < len-1; i++) {
|
|
116
|
+
newChildren.push(this.children[i]);
|
|
117
|
+
newChildren.push(aSep);
|
|
118
|
+
}
|
|
119
|
+
newChildren.push(this.children[i]);
|
|
120
|
+
this.children = newChildren;
|
|
121
|
+
}
|
|
122
|
+
return this;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Call String.prototype.replace on the very right-most source snippet. Useful
|
|
127
|
+
* for trimming whitespace from the end of a source node, etc.
|
|
128
|
+
*
|
|
129
|
+
* @param aPattern The pattern to replace.
|
|
130
|
+
* @param aReplacement The thing to replace the pattern with.
|
|
131
|
+
*/
|
|
132
|
+
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
|
133
|
+
var lastChild = this.children[this.children.length - 1];
|
|
134
|
+
if (lastChild instanceof SourceNode) {
|
|
135
|
+
lastChild.replaceRight(aPattern, aReplacement);
|
|
136
|
+
}
|
|
137
|
+
else if (typeof lastChild === 'string') {
|
|
138
|
+
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.children.push(''.replace(aPattern, aReplacement));
|
|
142
|
+
}
|
|
143
|
+
return this;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Return the string representation of this source node. Walks over the tree
|
|
148
|
+
* and concatenates all the various snippets together to one string.
|
|
149
|
+
*/
|
|
150
|
+
SourceNode.prototype.toString = function SourceNode_toString() {
|
|
151
|
+
var str = "";
|
|
152
|
+
this.walk(function (chunk) {
|
|
153
|
+
str += chunk;
|
|
154
|
+
});
|
|
155
|
+
return str;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns the string representation of this source node along with a source
|
|
160
|
+
* map.
|
|
161
|
+
*/
|
|
162
|
+
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
|
163
|
+
var generated = {
|
|
164
|
+
code: "",
|
|
165
|
+
line: 1,
|
|
166
|
+
column: 0
|
|
167
|
+
};
|
|
168
|
+
var map = new SourceMapGenerator(aArgs);
|
|
169
|
+
this.walk(function (chunk, original) {
|
|
170
|
+
generated.code += chunk;
|
|
171
|
+
if (original.source !== null
|
|
172
|
+
&& original.line !== null
|
|
173
|
+
&& original.column !== null) {
|
|
174
|
+
map.addMapping({
|
|
175
|
+
source: original.source,
|
|
176
|
+
original: {
|
|
177
|
+
line: original.line,
|
|
178
|
+
column: original.column
|
|
179
|
+
},
|
|
180
|
+
generated: {
|
|
181
|
+
line: generated.line,
|
|
182
|
+
column: generated.column
|
|
183
|
+
},
|
|
184
|
+
name: original.name
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
chunk.split('').forEach(function (ch) {
|
|
188
|
+
if (ch === '\n') {
|
|
189
|
+
generated.line++;
|
|
190
|
+
generated.column = 0;
|
|
191
|
+
} else {
|
|
192
|
+
generated.column++;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return { code: generated.code, map: map };
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
exports.SourceNode = SourceNode;
|
|
201
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
|
4
|
+
* Licensed under the New BSD license. See LICENSE or:
|
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
// Vendored into MambaScript from source-map 0.1.11 (BSD-3-Clause, see ../../LICENSE); amdefine wrapper removed.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This is a helper function for getting values from parameter/options
|
|
11
|
+
* objects.
|
|
12
|
+
*
|
|
13
|
+
* @param args The object we are extracting values from
|
|
14
|
+
* @param name The name of the property we are getting.
|
|
15
|
+
* @param defaultValue An optional value to return if the property is missing
|
|
16
|
+
* from the object. If this is not specified and the property is missing, an
|
|
17
|
+
* error will be thrown.
|
|
18
|
+
*/
|
|
19
|
+
function getArg(aArgs, aName, aDefaultValue) {
|
|
20
|
+
if (aName in aArgs) {
|
|
21
|
+
return aArgs[aName];
|
|
22
|
+
} else if (arguments.length === 3) {
|
|
23
|
+
return aDefaultValue;
|
|
24
|
+
} else {
|
|
25
|
+
throw new Error('"' + aName + '" is a required argument.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.getArg = getArg;
|
|
29
|
+
|
|
30
|
+
function join(aRoot, aPath) {
|
|
31
|
+
return aPath.charAt(0) === '/'
|
|
32
|
+
? aPath
|
|
33
|
+
: aRoot.replace(/\/*$/, '') + '/' + aPath;
|
|
34
|
+
}
|
|
35
|
+
exports.join = join;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Because behavior goes wacky when you set `__proto__` on objects, we
|
|
39
|
+
* have to prefix all the strings in our set with an arbitrary character.
|
|
40
|
+
*
|
|
41
|
+
* See https://github.com/mozilla/source-map/pull/31 and
|
|
42
|
+
* https://github.com/mozilla/source-map/issues/30
|
|
43
|
+
*
|
|
44
|
+
* @param String aStr
|
|
45
|
+
*/
|
|
46
|
+
function toSetString(aStr) {
|
|
47
|
+
return '$' + aStr
|
|
48
|
+
}
|
|
49
|
+
exports.toSetString = toSetString;
|
|
50
|
+
|
|
51
|
+
function relative(aRoot, aPath) {
|
|
52
|
+
return aPath.indexOf(aRoot.replace(/\/*$/, '') + '/') === 0
|
|
53
|
+
? aPath.substr(aRoot.length + 1)
|
|
54
|
+
: aPath;
|
|
55
|
+
}
|
|
56
|
+
exports.relative = relative;
|
|
57
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2009-2011 Mozilla Foundation and contributors
|
|
3
|
+
* Licensed under the New BSD license. See LICENSE.txt or:
|
|
4
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
exports.SourceMapGenerator = require('./source-map/source-map-generator').SourceMapGenerator;
|
|
7
|
+
exports.SourceMapConsumer = require('./source-map/source-map-consumer').SourceMapConsumer;
|
|
8
|
+
exports.SourceNode = require('./source-map/source-node').SourceNode;
|
package/bin/fix
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const { readdirSync, renameSync } = require('fs');
|
|
5
|
-
const [dir, search, replace] = process.argv.slice(2);
|
|
6
|
-
const match = RegExp(search, 'g');
|
|
7
|
-
const files = readdirSync(dir);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
files
|
|
11
|
-
.filter(file => file.match(match))
|
|
12
|
-
.forEach(file => {
|
|
13
|
-
const filePath = join(dir, file);
|
|
14
|
-
const newFilePath = join(dir, file.replace(match, replace));
|
|
15
|
-
|
|
16
|
-
renameSync(filePath, newFilePath);
|
|
17
|
-
});
|
package/bin/updateImports
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const FS = require('fs')
|
|
4
|
-
const globby = require('globby')
|
|
5
|
-
const r1 = /^([a-zA-Z_$][a-zA-Z0-9_$]*) +\= +(require)\((('|")[a-zA-Z0-9-_.\/@~]+('|"))\)/gm // const createStore = require('redux')
|
|
6
|
-
const r2 = /^([a-zA-Z_$][a-zA-Z0-9_$]*) +\= +(require)\((('|")[a-zA-Z0-9-_.\/@~]+('|"))\)\.([a-zA-Z][a-zA-Z0-9]*)/gm // const createStore = require('redux').createStore
|
|
7
|
-
const r3 = /^(\{\s*([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\}) +\= +(require)\((('|")[a-zA-Z0-9-_.\/@~]+('|"))\)/gm // const { createStore } = require('redux')
|
|
8
|
-
const r4 = /^(module.exports) +\= (([a-zA-Z_$][a-zA-Z0-9_$]*))/gm
|
|
9
|
-
const r5 = /^(eval)\(('|")(export)\s+(["'=a-zA-Z0-9-_.\s\/@~]+)('|")\)/gm
|
|
10
|
-
|
|
11
|
-
const args = process.argv.slice(2)
|
|
12
|
-
|
|
13
|
-
if (!args.length) {
|
|
14
|
-
console.error('Please pass a directory glob to "replace-require-with-import"\n')
|
|
15
|
-
process.exit(1)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const paths = globby.sync(args)
|
|
19
|
-
|
|
20
|
-
paths.forEach(function (p) {
|
|
21
|
-
if (!FS.statSync(p).isDirectory()) {
|
|
22
|
-
return replaceInFile(p)
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
function replaceInFile(fp) {
|
|
27
|
-
const result = FS.writeFileSync(fp, FS.readFileSync(fp, 'utf-8')
|
|
28
|
-
.replace(r2, `import { $6 as _$1 } from $3; \n $1 = _$1`)
|
|
29
|
-
.replace(r3, `import { _$2 } from $4; \n $2 = _$2`)
|
|
30
|
-
.replace(r4, `export default $3`)
|
|
31
|
-
.replace(r1, `import _$1 from $3; \n $1 = _$1`)
|
|
32
|
-
.replace(r5, `export $4`) ,'utf-8')
|
|
33
|
-
console.log(`> ${fp}`)
|
|
34
|
-
return result
|
|
35
|
-
}
|
|
36
|
-
console.info('Done!\n');
|
|
37
|
-
|
|
38
|
-
module.exports = function(code){
|
|
39
|
-
return (
|
|
40
|
-
code
|
|
41
|
-
.replace(r2, `import { $6 as _$1 } from $3; \n $1 = _$1`)
|
|
42
|
-
.replace(r3, `import { _$2 } from $4; \n $2 = _$2`)
|
|
43
|
-
.replace(r4, `export default $3`)
|
|
44
|
-
.replace(r1, `import _$1 from $3; \n $1 = _$1`)
|
|
45
|
-
)
|
|
46
|
-
}
|
package/build.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const exec = require('child_process').exec
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exec('npm run buildfiles', (err, stderr, stdout) => {
|
|
5
|
-
if(err){
|
|
6
|
-
console.error(error)
|
|
7
|
-
} else {
|
|
8
|
-
console.log(stderr)
|
|
9
|
-
console.log(stdout)
|
|
10
|
-
console.log("Build complete")
|
|
11
|
-
}
|
|
12
|
-
setTimeout(() => {
|
|
13
|
-
console.log('Preparing To Run Tests')
|
|
14
|
-
exec('npm run test', (err, stderr, stdout) => {
|
|
15
|
-
if(err){
|
|
16
|
-
console.error(err)
|
|
17
|
-
} else {
|
|
18
|
-
console.log(stderr)
|
|
19
|
-
console.log(stdout)
|
|
20
|
-
}
|
|
21
|
-
return
|
|
22
|
-
})
|
|
23
|
-
}, 5000)
|
|
24
|
-
return
|
|
25
|
-
})
|