Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "traceur", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Experimental ES6 to ES5 compiler", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"source-map": "0.1.16", | ||
"source-map": "0.1.30", | ||
"mocha": ">=1.9", | ||
@@ -41,0 +41,0 @@ "chai": ">=1.5" |
@@ -26,2 +26,3 @@ // Copyright 2013 Traceur Authors. | ||
var mkdirRecursive = util.mkdirRecursive; | ||
var normalizePath = util.normalizePath; | ||
@@ -50,4 +51,4 @@ var ErrorReporter = traceur.util.ErrorReporter; | ||
if (useSourceMaps) { | ||
compiledCode += '\n//@ sourceMappingURL=' + | ||
path.basename(sourceMapFilePath); | ||
compiledCode += '\n//# sourceMappingURL=' + | ||
path.basename(sourceMapFilePath) + '\n'; | ||
} | ||
@@ -74,3 +75,3 @@ writeFile(filename, compiledCode); | ||
resolvedIncludes = resolvedIncludes.map(function(include) { | ||
return path.relative(outputDir, include); | ||
return normalizePath(path.relative(outputDir, include)); | ||
}); | ||
@@ -77,0 +78,0 @@ |
@@ -67,4 +67,9 @@ // Copyright 2013 Traceur Authors. | ||
function normalizePath(s) { | ||
return path.sep == '\\' ? s.replace(/\\/g, '/') : s; | ||
} | ||
exports.mkdirRecursive = mkdirRecursive; | ||
exports.normalizePath = normalizePath; | ||
exports.removeCommonPrefix = removeCommonPrefix; | ||
exports.writeFile = writeFile; |
@@ -15,11 +15,12 @@ // Copyright 2012 Traceur Authors. | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var NodeLoader = require('./NodeLoader.js'); | ||
var normalizePath = require('./file-util.js').normalizePath; | ||
var generateNameForUrl = traceur.generateNameForUrl; | ||
var ErrorReporter = traceur.util.ErrorReporter; | ||
var InternalLoader = traceur.modules.internals.InternalLoader; | ||
var ModuleAnalyzer = traceur.semantics.ModuleAnalyzer; | ||
var ModuleDefinition = traceur.syntax.trees.ModuleDefinition; | ||
var ModuleRequireVisitor = traceur.codegeneration.module.ModuleRequireVisitor; | ||
@@ -31,3 +32,4 @@ var ModuleSymbol = traceur.semantics.symbols.ModuleSymbol; | ||
var Parser = traceur.syntax.Parser; | ||
var Program = traceur.syntax.trees.Program; | ||
var Script = traceur.syntax.trees.Script; | ||
var ModuleSpecifier = traceur.syntax.trees.ModuleSpecifier; | ||
var ProgramTransformer = traceur.codegeneration.ProgramTransformer; | ||
@@ -38,27 +40,10 @@ var Project = traceur.semantics.symbols.Project; | ||
var TreeWriter = traceur.outputgeneration.TreeWriter; | ||
var IDENTIFIER = traceur.syntax.TokenType.IDENTIFIER; | ||
var canonicalizeUrl = traceur.util.canonicalizeUrl; | ||
var createIdentifierExpression = ParseTreeFactory.createIdentifierExpression; | ||
var createIdentifierToken = ParseTreeFactory.createIdentifierToken; | ||
var resolveUrl = traceur.util.resolveUrl; | ||
var createStringLiteralToken = ParseTreeFactory.createStringLiteralToken; | ||
/** | ||
* Wraps a program in a module definition. | ||
* @param {ProgramTree} tree The original program tree. | ||
* @param {string} url The relative URL of the module that the program | ||
* represents. | ||
* @param {string} commonPath The base path of all the files. This is passed | ||
* along to |generateNameForUrl|. | ||
* @return {[ProgramTree} A new program tree with only one statement, which is | ||
* a module definition. | ||
*/ | ||
function wrapProgram(tree, url, commonPath) { | ||
var name = generateNameForUrl(url, commonPath); | ||
return new Program(null, | ||
[new ModuleDefinition(null, | ||
createIdentifierToken(name), tree.programElements)]); | ||
} | ||
/** | ||
* This transformer replaces | ||
* This resolves imported URLs for Script trees. | ||
* | ||
@@ -69,30 +54,25 @@ * import * from "url" | ||
* | ||
* import * from $_name_associated_with_url | ||
* import * from "resolved_url" | ||
* | ||
* @param {string} url The base URL that all the modules should be relative | ||
* to. | ||
* @param {string} commonPath The path that is common for all URLs. | ||
* @param {string} url The base URL that all the modules should be relative to. | ||
*/ | ||
function ModuleRequireTransformer(url, commonPath) { | ||
function ResolveImportUrlTransformer(url) { | ||
ParseTreeTransformer.call(this); | ||
this.url = url; | ||
this.commonPath = commonPath; | ||
} | ||
ModuleRequireTransformer.prototype = { | ||
ResolveImportUrlTransformer.prototype = { | ||
__proto__: ParseTreeTransformer.prototype, | ||
transformModuleRequire: function(tree) { | ||
var url = tree.url.processedValue; | ||
transformModuleSpecifier: function(tree) { | ||
var url = tree.token.processedValue; | ||
// Don't handle builtin modules. | ||
// Don't handle builtin modules. | ||
if (url.charAt(0) === '@') | ||
return tree; | ||
url = resolveUrl(this.url, url); | ||
return createIdentifierExpression(generateNameForUrl(url, this.commonPath)); | ||
url = System.normalResolve(url, this.url); | ||
return new ModuleSpecifier(tree.location, createStringLiteralToken(url)); | ||
} | ||
}; | ||
var startCodeUnit; | ||
/** | ||
@@ -109,3 +89,3 @@ * @param {ErrorReporter} reporter | ||
this.dirname = project.url; | ||
this.depTarget = depTarget && path.relative('.', depTarget); | ||
this.depTarget = depTarget && normalizePath(path.relative('.', depTarget)); | ||
this.codeUnitList = []; | ||
@@ -120,14 +100,19 @@ } | ||
var tree = codeUnit.transformedTree; | ||
this.elements.push.apply(this.elements, tree.programElements); | ||
this.elements.push.apply(this.elements, tree.scriptItemList); | ||
}, | ||
transformCodeUnit: function(codeUnit) { | ||
var transformer = new ModuleRequireTransformer(codeUnit.url, this.dirname); | ||
var tree = transformer.transformAny(codeUnit.tree); | ||
if (this.depTarget) | ||
if (this.depTarget) { | ||
console.log('%s: %s', this.depTarget, | ||
path.relative(path.join(__dirname, '../..'), codeUnit.url)); | ||
if (codeUnit === startCodeUnit) | ||
return tree; | ||
return wrapProgram(tree, codeUnit.url, this.dirname); | ||
normalizePath(path.relative(path.join(__dirname, '../..'), | ||
codeUnit.url))); | ||
} | ||
if (codeUnit.type === 'script') { | ||
var transformer = new ResolveImportUrlTransformer(codeUnit.url); | ||
var tree = transformer.transformAny(codeUnit.tree); | ||
this.project.setParseTree(codeUnit.file, tree); | ||
} | ||
return InternalLoader.prototype.transformCodeUnit.call(this, codeUnit); | ||
} | ||
@@ -137,14 +122,3 @@ }; | ||
function allLoaded(url, reporter, elements) { | ||
var project = new Project(url); | ||
var programTree = new Program(null, elements); | ||
var file = new SourceFile(project.url, '/* dummy */'); | ||
project.addFile(file); | ||
project.setParseTree(file, programTree); | ||
var analyzer = new ModuleAnalyzer(reporter, project); | ||
analyzer.analyze(); | ||
var transformer = new ProgramTransformer(reporter, project); | ||
return transformer.transform(programTree); | ||
return new Script(null, elements); | ||
} | ||
@@ -179,3 +153,2 @@ | ||
var codeUnit = loader.load(filenames[loadCount]); | ||
startCodeUnit = codeUnit; | ||
@@ -212,4 +185,3 @@ codeUnit.addListener(function() { | ||
filenames.forEach(function(filename) { | ||
filename = resolveUrl(basePath, filename); | ||
startCodeUnit = loader.getCodeUnit(filename); | ||
filename = System.normalResolve(filename, basePath); | ||
loader.loadSync(filename); | ||
@@ -216,0 +188,0 @@ }); |
@@ -21,4 +21,10 @@ // Copyright 2012 Traceur Authors. | ||
if (global.$traceurRuntime) { | ||
// Prevents from being executed multiple times. | ||
return; | ||
} | ||
var $create = Object.create; | ||
var $defineProperty = Object.defineProperty; | ||
var $defineProperties = Object.defineProperties; | ||
var $freeze = Object.freeze; | ||
@@ -28,2 +34,3 @@ var $getOwnPropertyNames = Object.getOwnPropertyNames; | ||
var $hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | ||
@@ -44,3 +51,3 @@ function nonEnum(value) { | ||
// http://wiki.ecmascript.org/doku.php?id=harmony:string_extras | ||
Object.defineProperties(String.prototype, { | ||
$defineProperties(String.prototype, { | ||
startsWith: method(function(s) { | ||
@@ -59,8 +66,36 @@ return this.lastIndexOf(s, 0) === 0; | ||
return this.split(''); | ||
}), | ||
codePointAt: method(function(position) { | ||
/*! http://mths.be/codepointat v0.1.0 by @mathias */ | ||
var string = String(this); | ||
var size = string.length; | ||
// `ToInteger` | ||
var index = position ? Number(position) : 0; | ||
if (isNaN(index)) { | ||
index = 0; | ||
} | ||
// Account for out-of-bounds indices: | ||
if (index < 0 || index >= size) { | ||
return undefined; | ||
} | ||
// Get the first code unit | ||
var first = string.charCodeAt(index); | ||
var second; | ||
if ( // check if it’s the start of a surrogate pair | ||
first >= 0xD800 && first <= 0xDBFF && // high surrogate | ||
size > index + 1 // there is a next code unit | ||
) { | ||
second = string.charCodeAt(index + 1); | ||
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; | ||
} | ||
} | ||
return first; | ||
}) | ||
}); | ||
// 15.5.3.4 String.raw ( callSite, ...substitutions) | ||
$defineProperty(String, 'raw', { | ||
value: function(callsite) { | ||
$defineProperties(String, { | ||
// 21.1.2.4 String.raw(callSite, ...substitutions) | ||
raw: method(function(callsite) { | ||
var raw = callsite.raw; | ||
@@ -78,6 +113,37 @@ var len = raw.length >>> 0; // ToUint | ||
} | ||
}, | ||
configurable: true, | ||
enumerable: false, | ||
writable: true | ||
}), | ||
// 21.1.2.2 String.fromCodePoint(...codePoints) | ||
fromCodePoint: method(function() { | ||
// http://mths.be/fromcodepoint v0.1.0 by @mathias | ||
var codeUnits = []; | ||
var floor = Math.floor; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
if (!length) { | ||
return ''; | ||
} | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
if (codePoint <= 0xFFFF) { // BMP code point | ||
codeUnits.push(codePoint); | ||
} else { // Astral code point; split in surrogate halves | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
} | ||
} | ||
return String.fromCharCode.apply(null, codeUnits); | ||
}) | ||
}); | ||
@@ -264,2 +330,3 @@ } | ||
} | ||
return object; | ||
} | ||
@@ -269,3 +336,3 @@ | ||
while (obj !== null) { | ||
var result = Object.getOwnPropertyDescriptor(obj, name); | ||
var result = $getOwnPropertyDescriptor(obj, name); | ||
if (result) | ||
@@ -308,2 +375,27 @@ return result; | ||
$defineProperty(Object, 'is', method(is)); | ||
// Object.assign (19.1.3.1) | ||
function assign(target, source) { | ||
var props = $getOwnPropertyNames(source); | ||
var p, length = props.length; | ||
for (p = 0; p < length; p++) { | ||
target[props[p]] = source[props[p]]; | ||
} | ||
return target; | ||
} | ||
$defineProperty(Object, 'assign', method(assign)); | ||
// Object.mixin (19.1.3.15) | ||
function mixin(target, source) { | ||
var props = $getOwnPropertyNames(source); | ||
var p, descriptor, length = props.length; | ||
for (p = 0; p < length; p++) { | ||
descriptor = $getOwnPropertyDescriptor(source, props[p]); | ||
$defineProperty(target, props[p], descriptor); | ||
} | ||
return target; | ||
} | ||
$defineProperty(Object, 'mixin', method(mixin)); | ||
} | ||
@@ -439,3 +531,3 @@ | ||
var modules = $freeze({ | ||
var modules = { | ||
get '@name'() { | ||
@@ -447,6 +539,13 @@ return NameModule; | ||
} | ||
}); | ||
}; | ||
// TODO(arv): Don't export this. | ||
global.Deferred = Deferred; | ||
// This gets overridden in @traceur/modules to be more correct. | ||
var System = { | ||
get: function(name) { | ||
return modules[name] || null; | ||
}, | ||
set: function(name, object) { | ||
modules[name] = object; | ||
} | ||
}; | ||
@@ -457,2 +556,5 @@ function setupGlobals(global) { | ||
polyfillArray(global.Array); | ||
global.System = System; | ||
// TODO(arv): Don't export this. | ||
global.Deferred = Deferred; | ||
} | ||
@@ -478,3 +580,2 @@ | ||
has: has, | ||
modules: modules, | ||
}; | ||
@@ -481,0 +582,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
874004
22148