Skip to content

Commit

Permalink
Change var to let/const
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Feb 20, 2015
1 parent c017f1d commit 0b17757
Show file tree
Hide file tree
Showing 111 changed files with 2,113 additions and 2,006 deletions.
6 changes: 3 additions & 3 deletions build/build-parse-tree-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ function printTransformBody(name, tree, trees) {
var fieldTypes = tree[fieldName];
var fieldType = fieldTypes[0];
if (util.isBlockOrStatementType(fieldTypes, trees)) {
util.print(' var ' + fieldName +
util.print(' let ' + fieldName +
' = this.transformToBlockOrStatement(tree.' + fieldName +
');');
addTest(fieldName);
} else if (util.isParseTreeType(fieldType, trees)) {
util.print(' var ' + fieldName + ' = this.transformAny(tree.' +
util.print(' let ' + fieldName + ' = this.transformAny(tree.' +
fieldName + ');');
addTest(fieldName);
} else if (util.isParseTreeListType(fieldType, trees)) {
util.print(' var ' + fieldName + ' = this.transformList(tree.' +
util.print(' let ' + fieldName + ' = this.transformList(tree.' +
fieldName + ');');
addTest(fieldName);
} else {
Expand Down
2 changes: 1 addition & 1 deletion build/build-parse-tree-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ names.sort();

names.forEach(function(name) {
name = util.toConstantName(name);
print('export var %s = \'%s\';', name, name);
print('export const %s = \'%s\';', name, name);
});
4 changes: 2 additions & 2 deletions build/build-parse-trees.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ util.printAutoGenerated();
print("import {ParseTree} from './ParseTree.js';");
print("import * as ParseTreeType from './ParseTreeType.js';");

// export var ARGUMENT_LIST = 'ARGUMENT_LIST';
// export const ARGUMENT_LIST = 'ARGUMENT_LIST';
var data = fs.readFileSync(process.argv[2], 'utf-8');
var trees = util.parseJSON(data);

Expand All @@ -49,7 +49,7 @@ names.forEach(function(name) {
// var params = trees[name];
// var paramNames = params.map(function(p) { return p.name; });
print();
print('var %s = ParseTreeType.%s;', treeTypeName, treeTypeName);
print('const %s = ParseTreeType.%s;', treeTypeName, treeTypeName);
print('export class %s extends ParseTree {', name);
print(' /**');
paramNames.forEach(function(paramName) {
Expand Down
2 changes: 1 addition & 1 deletion build/build-unicode-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var unicodeIdContinue = [];
var idStartRanges = {};

function printArray(name, array) {
print('export var ' + name + ' = [');
print('export const ' + name + ' = [');
for (var i = 0; i < array.length; i += 2) {
print(' ' + array[i] + ', ' + array[i + 1] + ',');
}
Expand Down
10 changes: 5 additions & 5 deletions build/parse-tree-transformer.header
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export class ParseTreeTransformer {
return tree && tree.transform(this);
}
transformList(list) {
var builder = null;
for (var index = 0; index < list.length; index++) {
var element = list[index];
var transformed = this.transformAny(element);
let builder = null;
for (let index = 0; index < list.length; index++) {
let element = list[index];
let transformed = this.transformAny(element);
if (builder != null || element != transformed) {
if (builder == null) {
builder = list.slice(0, index);
Expand All @@ -23,7 +23,7 @@ export class ParseTreeTransformer {
throw Error('State machines should not live outside of the GeneratorTransformer.');
}
transformToBlockOrStatement(tree) {
var transformed = this.transformAny(tree);
let transformed = this.transformAny(tree);
if (transformed instanceof AnonBlock) {
return new Block(transformed.location, transformed.statements);
}
Expand Down
2 changes: 1 addition & 1 deletion build/parse-tree-visitor.header
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ParseTreeVisitor {
}
visitList(list) {
if (list) {
for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
this.visitAny(list[i]);
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
} from './outputgeneration/SourceMapIntegration.js';

function merge(...srcs) {
var dest = Object.create(null);
let dest = Object.create(null);
srcs.forEach((src) => {
Object.keys(src).forEach((key) => {
dest[key] = src[key];
});
var srcModules = src.modules; // modules is a getter on prototype
let srcModules = src.modules; // modules is a getter on prototype
if (typeof srcModules !== 'undefined') {
dest.modules = srcModules;
}
Expand All @@ -46,7 +46,7 @@ function merge(...srcs) {
function basePath(name) {
if (!name)
return null;
var lastSlash = name.lastIndexOf('/');
let lastSlash = name.lastIndexOf('/');
if (lastSlash < 0)
return null;
return name.substring(0, lastSlash + 1);
Expand Down Expand Up @@ -98,7 +98,7 @@ export class Compiler {
* @return {Object}
*/
static amdOptions(options = {}) {
var amdOptions = {
let amdOptions = {
modules: 'amd',
sourceMaps: false,
moduleName: false
Expand All @@ -112,7 +112,7 @@ export class Compiler {
* @return {Object}
*/
static closureOptions(options = {}) {
var closureOptions = {
let closureOptions = {
modules: 'closure',
sourceMaps: false,
moduleName: true
Expand All @@ -126,7 +126,7 @@ export class Compiler {
* @return {Object}
*/
static commonJSOptions(options = {}) {
var commonjsOptions = {
let commonjsOptions = {
modules: 'commonjs',
sourceMaps: false,
moduleName: false
Expand All @@ -148,10 +148,10 @@ export class Compiler {

sourceName = this.normalize(sourceName);
outputName = this.normalize(outputName);
var tree = this.parse(content, sourceName);
let tree = this.parse(content, sourceName);
tree = this.transform(tree, sourceName);
// Attach the sourceURL only if the input and output names differ.
var sourceURL = sourceName !== outputName ? sourceName : undefined;
let sourceURL = sourceName !== outputName ? sourceName : undefined;
// The sourceRoot argument takes precidence over the option.
if (sourceRoot === undefined)
sourceRoot = this.options_.sourceRoot;
Expand All @@ -173,10 +173,10 @@ export class Compiler {
this.sourceMapCache_ = null;
this.sourceMapConfiguration_ = null;

var errorReporter = new CollectingErrorReporter();
var sourceFile = new SourceFile(sourceName, content);
var parser = new Parser(sourceFile, errorReporter, this.options_);
var tree =
let errorReporter = new CollectingErrorReporter();
let sourceFile = new SourceFile(sourceName, content);
let parser = new Parser(sourceFile, errorReporter, this.options_);
let tree =
this.options_.script ? parser.parseScript() : parser.parseModule();
this.throwIfErrors(errorReporter);

Expand All @@ -192,21 +192,21 @@ export class Compiler {
*/
transform(tree, candidateModuleName = undefined) {

var transformer;
let transformer;
if (candidateModuleName) {
var transformer = new AttachModuleNameTransformer(candidateModuleName);
let transformer = new AttachModuleNameTransformer(candidateModuleName);
tree = transformer.transformAny(tree);
}

var errorReporter = new CollectingErrorReporter();
let errorReporter = new CollectingErrorReporter();

if (this.options_.outputLanguage.toLowerCase() === 'es6') {
transformer = new PureES6Transformer(errorReporter, this.options_);
} else {
transformer = new FromOptionsTransformer(errorReporter, this.options_);
}

var transformedTree = transformer.transform(tree);
let transformedTree = transformer.transform(tree);
this.throwIfErrors(errorReporter);
return transformedTree;
}
Expand All @@ -231,10 +231,10 @@ export class Compiler {
}

if (this.sourceMapConfiguration_) {
var sourceMap = this.sourceMapConfiguration_.sourceMapGenerator.toString();
var inputSourceMap = this.sourceMapConfiguration_.inputSourceMap;
let sourceMap = this.sourceMapConfiguration_.sourceMapGenerator.toString();
let inputSourceMap = this.sourceMapConfiguration_.inputSourceMap;
if (inputSourceMap) {
var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
let generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
generator.applySourceMap(new SourceMapConsumer(inputSourceMap));
sourceMap = generator.toJSON();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class Compiler {
else
sourceRoot = this.normalize(sourceRoot);

var writer;
let writer;
this.sourceMapCache_ = null;
this.sourceMapConfiguration_ =
this.createSourceMapConfiguration_(outputName, sourceRoot);
Expand All @@ -284,12 +284,12 @@ export class Compiler {

writer.visitAny(tree);

var compiledCode = writer.toString();
let compiledCode = writer.toString();

if (this.sourceMapConfiguration_) {
var sourceMappingURL =
let sourceMappingURL =
this.sourceMappingURL(sourceURL || outputName || 'unnamed.js');
var sourceMap = this.getSourceMap();
let sourceMap = this.getSourceMap();
compiledCode += '\n//# sourceMappingURL=' + sourceMappingURL + '\n';
// The source map info for in-memory maps
this.sourceMapInfo_ = {
Expand Down
44 changes: 22 additions & 22 deletions src/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@


function enumerableOnlyObject(obj) {
var result = Object.create(null);
let result = Object.create(null);
Object.keys(obj).forEach(function(key) {
Object.defineProperty(result, key, {enumerable: true, value: obj[key]});
});
return result;
}

// Traceur sets these default options and no others for v 0.1.*
export var optionsV01 = enumerableOnlyObject({
export const optionsV01 = enumerableOnlyObject({
annotations: false,
arrayComprehension: false,
arrowFunctions: true,
Expand Down Expand Up @@ -69,7 +69,7 @@ export var optionsV01 = enumerableOnlyObject({
validate: false,
});

export var versionLockedOptions = optionsV01;
export const versionLockedOptions = optionsV01;

// Options are just a plain old object. There are two read only views on this
// object, parseOptions and transformOptions.
Expand All @@ -87,14 +87,14 @@ export var versionLockedOptions = optionsV01;
// This allows you to parse certain features without transforming them, leaving
// the syntax intact in the output.

var defaultValues = Object.create(null);
var featureOptions = Object.create(null);
var experimentalOptions = Object.create(null);
var moduleOptions =
let defaultValues = Object.create(null);
let featureOptions = Object.create(null);
let experimentalOptions = Object.create(null);
let moduleOptions =
['amd', 'commonjs', 'closure', 'instantiate', 'inline', 'register'];

var EXPERIMENTAL = 0;
var ON_BY_DEFAULT = 1;
const EXPERIMENTAL = 0;
const ON_BY_DEFAULT = 1;

/**
* Adds a feature option. Feature options can be tested with parseOptions
Expand All @@ -106,7 +106,7 @@ function addFeatureOption(name, kind) {
if (kind === EXPERIMENTAL)
experimentalOptions[name] = true;

var defaultValue = kind === ON_BY_DEFAULT;
let defaultValue = kind === ON_BY_DEFAULT;
defaultValues[name] = defaultValue;
}

Expand Down Expand Up @@ -153,12 +153,12 @@ addFeatureOption('memberVariables', EXPERIMENTAL);
addFeatureOption('require', EXPERIMENTAL);
addFeatureOption('types', EXPERIMENTAL);

var transformOptionsPrototype = {};
let transformOptionsPrototype = {};

Object.keys(featureOptions).forEach((name) => {
Object.defineProperty(transformOptionsPrototype, name, {
get: function() {
var v = this.proxiedOptions_[name];
let v = this.proxiedOptions_[name];
if (v === 'parse')
return false;
return v;
Expand All @@ -167,7 +167,7 @@ Object.keys(featureOptions).forEach((name) => {
});
});

var parseOptionsPrototype = {};
let parseOptionsPrototype = {};

Object.keys(featureOptions).forEach((name) => {
Object.defineProperty(parseOptionsPrototype, name, {
Expand Down Expand Up @@ -244,9 +244,9 @@ export class Options {
}

get experimental() {
var value;
let value;
Object.keys(experimentalOptions).every((name) => {
var currentValue = this[name];
let currentValue = this[name];
if (value === undefined) {
value = currentValue;
return true;
Expand Down Expand Up @@ -321,7 +321,7 @@ export class Options {
* @param {boolean=} allOff
*/
reset(allOff = undefined) {
var useDefault = allOff === undefined;
let useDefault = allOff === undefined;
Object.keys(defaultValues).forEach((name) => {
this[name] = useDefault && defaultValues[name];
});
Expand Down Expand Up @@ -370,7 +370,7 @@ export class Options {
}

diff(ref) {
var mismatches = [];
let mismatches = [];
Object.keys(this).forEach((key) => {
if (this[key] !== ref[key]) {
mismatches.push({
Expand All @@ -387,7 +387,7 @@ export class Options {


// TODO: Refactor this so that we can keep all of these in one place.
var descriptions = {
let descriptions = {
experimental: 'Turns on all experimental features',
require: 'Generate require function argument for node when modules=register',
sourceMaps: 'Generate source map and (\'file\') write to .map' +
Expand All @@ -408,7 +408,7 @@ export class CommandOptions extends Options {
* Takes an array of command line params and sets the options based on that.
*/
static fromArgv(args) {
var options = new CommandOptions();
let options = new CommandOptions();
args.forEach((arg) => options.parseCommand(arg));
return options;
}
Expand All @@ -423,8 +423,8 @@ export class CommandOptions extends Options {
* --modules=amd
*/
parseCommand(s) {
var re = /--([^=]+)(?:=(.+))?/;
var m = re.exec(s);
let re = /--([^=]+)(?:=(.+))?/;
let m = re.exec(s);

if (m)
this.setOptionCoerced(m[1], m[2]);
Expand Down Expand Up @@ -548,7 +548,7 @@ export function addOptions(flags, commandOptions) {
);

Object.keys(commandOptions).forEach(function(name) {
var dashedName = toDashCase(name);
let dashedName = toDashCase(name);
if (flags.optionFor('--' + name) || flags.optionFor('--' + dashedName)) {
return; // non-boolean already in flags.
} else if (name in featureOptions) {
Expand Down
Loading

0 comments on commit 0b17757

Please sign in to comment.