Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Node.replace()

Used by importer to replace importNode with rootNode
Remove _.extend()
  • Loading branch information...
commit 3779557efb912d91c3b4bcb62cfe0566ffac77b9 1 parent 9fbd09a
@curvedmark authored
View
1  .jshintrc
@@ -4,7 +4,6 @@
"camelcase": true,
"curly": true,
"eqeqeq": true,
- "forin": true,
"immed": true,
"noempty": true,
"newcap": false,
View
1  lib/evaluator/evaluator.js
@@ -7,7 +7,6 @@
var Visitor = require('../visitor');
var Scope = require('./scope');
-
var Evaluator = module.exports = function() {};
Evaluator.prototype = new Visitor();
View
13 lib/helper.js
@@ -9,19 +9,6 @@ var _ = exports;
_.noop = function() {};
-_.extend = function(target) {
- for (var i = 1, length = arguments.length; i < length; ++i) {
- var obj = arguments[i];
- for (var key in obj) {
- if (obj.hasOwnProperty(key) && obj[key] !== undefined) {
- target[key] = obj[key];
- }
- }
- }
-
- return target;
-};
-
_.capitalize = function(string) {
return string.charAt(0).toUpperCase() + string.substr(1);
};
View
9 lib/importer/importer.js
@@ -6,6 +6,7 @@
'use strict';
var _ = require('../helper');
+var Node = require('../node');
var Visitor = require('../visitor');
var loader = require('./fs-loader');
var parser = require('../parser');
@@ -99,17 +100,17 @@ Importer.prototype.visitImport = function(importNode) {
return callback(error);
}
- var ast;
+ var rootNode;
try {
this.imports[filePath] = content;
- ast = parser.parse(content, {filePath: filePath});
- this.visit(ast);
+ rootNode = parser.parse(content, {filePath: filePath});
+ this.visit(rootNode);
} catch (error) {
this.hasError = true;
return callback(error);
}
- _.extend(importNode, ast);
+ Node.replace(rootNode, importNode);
if (!--this.importing) {
callback(null, this.ast);
View
8 lib/node.js
@@ -38,6 +38,14 @@ Node.clone = function(node, deep) {
return clone;
};
+Node.replace = function(newNode, oldNode) {
+ for (var key in newNode) {
+ oldNode[key] = newNode[key];
+ }
+
+ return oldNode;
+};
+
Node.equal = function(node1, node2) {
if (Array.isArray(node1) || Array.isArray(node2)) {
if (!Array.isArray(node1) || !Array.isArray(node2)) {
View
1  lib/normalizer/normalizer.js
@@ -7,7 +7,6 @@
var _ = require('../helper');
var Visitor = require('../visitor');
-
var Normalizer = module.exports = function() {};
Normalizer.prototype = new Visitor();
Please sign in to comment.
Something went wrong with that request. Please try again.