Use proper default vs. module import semantics

This commit is contained in:
kpdecker
2013-10-01 21:19:49 -05:00
parent e75839b185
commit e676e43dc5
5 changed files with 37 additions and 40 deletions
+26 -30
View File
@@ -1,14 +1,12 @@
import Exception from "../exception"; import Exception from "../exception";
var exports = {}; export function ProgramNode(statements, inverse) {
exports.ProgramNode = function ProgramNode(statements, inverse) {
this.type = "program"; this.type = "program";
this.statements = statements; this.statements = statements;
if(inverse) { this.inverse = new ProgramNode(inverse); } if(inverse) { this.inverse = new ProgramNode(inverse); }
}; }
exports.MustacheNode = function(rawParams, hash, unescaped) { export function MustacheNode(rawParams, hash, unescaped) {
this.type = "mustache"; this.type = "mustache";
this.escaped = !unescaped; this.escaped = !unescaped;
this.hash = hash; this.hash = hash;
@@ -28,15 +26,15 @@ exports.MustacheNode = function(rawParams, hash, unescaped) {
// if a mustache is an eligible helper but not a definite // if a mustache is an eligible helper but not a definite
// helper, it is ambiguous, and will be resolved in a later // helper, it is ambiguous, and will be resolved in a later
// pass or at runtime. // pass or at runtime.
}; }
exports.PartialNode = function(partialName, context) { export function PartialNode(partialName, context) {
this.type = "partial"; this.type = "partial";
this.partialName = partialName; this.partialName = partialName;
this.context = context; this.context = context;
}; }
exports.BlockNode = function(mustache, program, inverse, close) { export function BlockNode(mustache, program, inverse, close) {
if(mustache.id.original !== close.original) { if(mustache.id.original !== close.original) {
throw new Exception(mustache.id.original + " doesn't match " + close.original); throw new Exception(mustache.id.original + " doesn't match " + close.original);
} }
@@ -49,19 +47,19 @@ exports.BlockNode = function(mustache, program, inverse, close) {
if (this.inverse && !this.program) { if (this.inverse && !this.program) {
this.isInverse = true; this.isInverse = true;
} }
}; }
exports.ContentNode = function(string) { export function ContentNode(string) {
this.type = "content"; this.type = "content";
this.string = string; this.string = string;
}; }
exports.HashNode = function(pairs) { export function HashNode(pairs) {
this.type = "hash"; this.type = "hash";
this.pairs = pairs; this.pairs = pairs;
}; }
exports.IdNode = function(parts) { export function IdNode(parts) {
this.type = "ID"; this.type = "ID";
var original = "", var original = "",
@@ -90,41 +88,39 @@ exports.IdNode = function(parts) {
this.isSimple = parts.length === 1 && !this.isScoped && depth === 0; this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
this.stringModeValue = this.string; this.stringModeValue = this.string;
}; }
exports.PartialNameNode = function(name) { export function PartialNameNode(name) {
this.type = "PARTIAL_NAME"; this.type = "PARTIAL_NAME";
this.name = name.original; this.name = name.original;
}; }
exports.DataNode = function(id) { export function DataNode(id) {
this.type = "DATA"; this.type = "DATA";
this.id = id; this.id = id;
}; }
exports.StringNode = function(string) { export function StringNode(string) {
this.type = "STRING"; this.type = "STRING";
this.original = this.original =
this.string = this.string =
this.stringModeValue = string; this.stringModeValue = string;
}; }
exports.IntegerNode = function(integer) { export function IntegerNode(integer) {
this.type = "INTEGER"; this.type = "INTEGER";
this.original = this.original =
this.integer = integer; this.integer = integer;
this.stringModeValue = Number(integer); this.stringModeValue = Number(integer);
}; }
exports.BooleanNode = function(bool) { export function BooleanNode(bool) {
this.type = "BOOLEAN"; this.type = "BOOLEAN";
this.bool = bool; this.bool = bool;
this.stringModeValue = bool === "true"; this.stringModeValue = bool === "true";
}; }
exports.CommentNode = function(comment) { export function CommentNode(comment) {
this.type = "comment"; this.type = "comment";
this.comment = comment; this.comment = comment;
}; }
export default exports;
+1 -1
View File
@@ -1,5 +1,5 @@
import parser from "./parser"; import parser from "./parser";
import AST from "./ast"; module AST from "./ast";
export var parser = parser; export var parser = parser;
+5 -7
View File
@@ -1,12 +1,10 @@
import Exception from "../exception"; import Exception from "../exception";
import { template } from "../runtime"; import { template } from "../runtime";
import { parse } from "./base"; import { parse } from "./base";
import { JavaScriptCompiler } from "./javascript-compiler"; import JavaScriptCompiler from "./javascript-compiler";
import AST from "./ast"; module AST from "./ast";
/*jshint eqnull:true*/ export function Compiler() {}
export function Compiler() {};
// the foundHelper register will disambiguate helper lookup from finding a // the foundHelper register will disambiguate helper lookup from finding a
// function in a context. This is necessary for mustache compatibility, which // function in a context. This is necessary for mustache compatibility, which
@@ -428,7 +426,7 @@ export function precompile(input, options) {
var ast = parse(input); var ast = parse(input);
var environment = new Compiler().compile(ast, options); var environment = new Compiler().compile(ast, options);
return new JavaScriptCompiler().compile(environment, options); return new JavaScriptCompiler().compile(environment, options);
}; }
export function compile(input, options) { export function compile(input, options) {
if (input == null || (typeof input !== 'string' && input.constructor !== AST.ProgramNode)) { if (input == null || (typeof input !== 'string' && input.constructor !== AST.ProgramNode)) {
@@ -457,4 +455,4 @@ export function compile(input, options) {
} }
return compiled.call(this, context, options); return compiled.call(this, context, options);
}; };
}; }
@@ -4,7 +4,7 @@ function Literal(value) {
this.value = value; this.value = value;
} }
export function JavaScriptCompiler() {}; function JavaScriptCompiler() {}
JavaScriptCompiler.prototype = { JavaScriptCompiler.prototype = {
// PUBLIC API: You can override these methods in a subclass to provide // PUBLIC API: You can override these methods in a subclass to provide
@@ -841,3 +841,4 @@ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
return false; return false;
}; };
export default JavaScriptCompiler;
+3 -1
View File
@@ -1,4 +1,4 @@
export function Visitor() {}; function Visitor() {}
Visitor.prototype = { Visitor.prototype = {
constructor: Visitor, constructor: Visitor,
@@ -7,3 +7,5 @@ Visitor.prototype = {
return this[object.type](object); return this[object.type](object);
} }
}; };
export default Visitor;