Skip to content

Commit

Permalink
Fixes #545, updates of esprima and uglifyjs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Oct 7, 2013
1 parent bffea98 commit 51781ff
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 185 deletions.
36 changes: 18 additions & 18 deletions build/jslib/esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,19 +968,19 @@ parseStatement: true, parseSourceElement: true */
while (index < length) {
ch = source[index++];
str += ch;
if (classMarker) {
if (ch === '\\') {
ch = source[index++];
// ECMA-262 7.8.5
if (isLineTerminator(ch)) {
throwError({}, Messages.UnterminatedRegExp);
}
str += ch;
} else if (classMarker) {
if (ch === ']') {
classMarker = false;
}
} else {
if (ch === '\\') {
ch = source[index++];
// ECMA-262 7.8.5
if (isLineTerminator(ch)) {
throwError({}, Messages.UnterminatedRegExp);
}
str += ch;
} else if (ch === '/') {
if (ch === '/') {
terminated = true;
break;
} else if (ch === '[') {
Expand Down Expand Up @@ -1712,9 +1712,8 @@ parseStatement: true, parseSourceElement: true */
if (strict && expr.type === Syntax.Identifier && isRestrictedWord(expr.name)) {
throwErrorTolerant({}, Messages.StrictLHSPostfix);
}

if (!isLeftHandSide(expr)) {
throwError({}, Messages.InvalidLHSInAssignment);
throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
}

expr = {
Expand Down Expand Up @@ -1747,7 +1746,7 @@ parseStatement: true, parseSourceElement: true */
}

if (!isLeftHandSide(expr)) {
throwError({}, Messages.InvalidLHSInAssignment);
throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
}

expr = {
Expand Down Expand Up @@ -1996,7 +1995,7 @@ parseStatement: true, parseSourceElement: true */
if (matchAssign()) {
// LeftHandSideExpression
if (!isLeftHandSide(expr)) {
throwError({}, Messages.InvalidLHSInAssignment);
throwErrorTolerant({}, Messages.InvalidLHSInAssignment);
}

// 11.13.1
Expand Down Expand Up @@ -2314,7 +2313,7 @@ parseStatement: true, parseSourceElement: true */
if (matchKeyword('in')) {
// LeftHandSideExpression
if (!isLeftHandSide(init)) {
throwError({}, Messages.InvalidLHSInForIn);
throwErrorTolerant({}, Messages.InvalidLHSInForIn);
}

lex();
Expand Down Expand Up @@ -2593,16 +2592,17 @@ parseStatement: true, parseSourceElement: true */

expect('{');

cases = [];

if (match('}')) {
lex();
return {
type: Syntax.SwitchStatement,
discriminant: discriminant
discriminant: discriminant,
cases: cases
};
}

cases = [];

oldInSwitch = state.inSwitch;
state.inSwitch = true;
defaultFound = false;
Expand Down Expand Up @@ -3879,7 +3879,7 @@ parseStatement: true, parseSourceElement: true */
}

// Sync with package.json.
exports.version = '1.0.3';
exports.version = '1.0.4';

exports.parse = parse;

Expand Down
19 changes: 10 additions & 9 deletions build/jslib/source-map/array-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ define(function (require, exports, module) {
/**
* Static method for creating ArraySet instances from an existing array.
*/
ArraySet.fromArray = function ArraySet_fromArray(aArray) {
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
var set = new ArraySet();
for (var i = 0, len = aArray.length; i < len; i++) {
set.add(aArray[i]);
set.add(aArray[i], aAllowDuplicates);
}
return set;
};
Expand All @@ -36,14 +36,15 @@ define(function (require, exports, module) {
*
* @param String aStr
*/
ArraySet.prototype.add = function ArraySet_add(aStr) {
if (this.has(aStr)) {
// Already a member; nothing to do.
return;
}
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
var isDuplicate = this.has(aStr);
var idx = this._array.length;
this._array.push(aStr);
this._set[util.toSetString(aStr)] = idx;
if (!isDuplicate || aAllowDuplicates) {
this._array.push(aStr);
}
if (!isDuplicate) {
this._set[util.toSetString(aStr)] = idx;
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion build/jslib/source-map/binary-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(function (require, exports, module) {
// element which is less than the one we are searching for, so we
// return null.
var mid = Math.floor((aHigh - aLow) / 2) + aLow;
var cmp = aCompare(aNeedle, aHaystack[mid]);
var cmp = aCompare(aNeedle, aHaystack[mid], true);
if (cmp === 0) {
// Found the element we are looking for.
return aHaystack[mid];
Expand Down
72 changes: 36 additions & 36 deletions build/jslib/source-map/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ define(function (require, exports, module) {
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
var mappings = util.getArg(sourceMap, 'mappings');
var file = util.getArg(sourceMap, 'file');
var file = util.getArg(sourceMap, 'file', null);

if (version !== this._version) {
throw new Error('Unsupported version: ' + version);
}

this._names = ArraySet.fromArray(names);
this._sources = ArraySet.fromArray(sources);
// Pass `true` below to allow duplicate names and sources. While source maps
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
// #72 and bugzil.la/889492.
this._names = ArraySet.fromArray(names, true);
this._sources = ArraySet.fromArray(sources, true);
this.sourceRoot = sourceRoot;
this.sourcesContent = sourcesContent;
this.file = file;
Expand Down Expand Up @@ -94,6 +98,32 @@ define(function (require, exports, module) {
this._parseMappings(mappings, sourceRoot);
}

/**
* Create a SourceMapConsumer from a SourceMapGenerator.
*
* @param SourceMapGenerator aSourceMap
* The source map that will be consumed.
* @returns SourceMapConsumer
*/
SourceMapConsumer.fromSourceMap =
function SourceMapConsumer_fromSourceMap(aSourceMap) {
var smc = Object.create(SourceMapConsumer.prototype);

smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
smc.sourceRoot = aSourceMap._sourceRoot;
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
smc.sourceRoot);
smc.file = aSourceMap._file;

smc._generatedMappings = aSourceMap._mappings.slice()
.sort(util.compareByGeneratedPositions);
smc._originalMappings = aSourceMap._mappings.slice()
.sort(util.compareByOriginalPositions);

return smc;
};

/**
* The version of the source mapping spec that we are consuming.
*/
Expand Down Expand Up @@ -189,37 +219,7 @@ define(function (require, exports, module) {
}
}

this._originalMappings.sort(this._compareOriginalPositions);
};

/**
* Comparator between two mappings where the original positions are compared.
*/
SourceMapConsumer.prototype._compareOriginalPositions =
function SourceMapConsumer_compareOriginalPositions(mappingA, mappingB) {
if (mappingA.source > mappingB.source) {
return 1;
}
else if (mappingA.source < mappingB.source) {
return -1;
}
else {
var cmp = mappingA.originalLine - mappingB.originalLine;
return cmp === 0
? mappingA.originalColumn - mappingB.originalColumn
: cmp;
}
};

/**
* Comparator between two mappings where the generated positions are compared.
*/
SourceMapConsumer.prototype._compareGeneratedPositions =
function SourceMapConsumer_compareGeneratedPositions(mappingA, mappingB) {
var cmp = mappingA.generatedLine - mappingB.generatedLine;
return cmp === 0
? mappingA.generatedColumn - mappingB.generatedColumn
: cmp;
this._originalMappings.sort(util.compareByOriginalPositions);
};

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ define(function (require, exports, module) {
this._generatedMappings,
"generatedLine",
"generatedColumn",
this._compareGeneratedPositions);
util.compareByGeneratedPositions);

if (mapping) {
var source = util.getArg(mapping, 'source', null);
Expand Down Expand Up @@ -366,7 +366,7 @@ define(function (require, exports, module) {
this._originalMappings,
"originalLine",
"originalColumn",
this._compareOriginalPositions);
util.compareByOriginalPositions);

if (mapping) {
return {
Expand Down
Loading

0 comments on commit 51781ff

Please sign in to comment.