mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Improved how tags are discovered and merged
This commit is contained in:
parent
41b2c0878a
commit
6e17698a5c
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
var taglibLoader = require('../taglib-loader');
|
var taglibLoader = require('../taglib-loader');
|
||||||
var nodePath = require('path');
|
var nodePath = require('path');
|
||||||
var fs = require('fs');
|
|
||||||
var lassoPackageRoot = require('lasso-package-root');
|
var lassoPackageRoot = require('lasso-package-root');
|
||||||
var resolveFrom = require('resolve-from');
|
var resolveFrom = require('resolve-from');
|
||||||
var scanTagsDir = require('../taglib-loader/scanTagsDir');
|
var scanTagsDir = require('../taglib-loader/scanTagsDir');
|
||||||
var Taglib = require('../taglib-loader/Taglib');
|
var Taglib = require('../taglib-loader/Taglib');
|
||||||
var DependencyChain = require('../taglib-loader/DependencyChain');
|
var DependencyChain = require('../taglib-loader/DependencyChain');
|
||||||
|
var lassoCachingFS = require('lasso-caching-fs');
|
||||||
|
|
||||||
var existsCache = {};
|
|
||||||
var findCache = {};
|
var findCache = {};
|
||||||
var excludedDirs = {};
|
var excludedDirs = {};
|
||||||
var excludedPackages = {};
|
var excludedPackages = {};
|
||||||
@ -20,7 +19,7 @@ var taglibsForNodeModulesDirCache = {};
|
|||||||
* was added for testing purposes.
|
* was added for testing purposes.
|
||||||
*/
|
*/
|
||||||
function reset() {
|
function reset() {
|
||||||
existsCache = {};
|
lassoCachingFS.clearCaches();
|
||||||
findCache = {};
|
findCache = {};
|
||||||
excludedDirs = {};
|
excludedDirs = {};
|
||||||
excludedPackages = {};
|
excludedPackages = {};
|
||||||
@ -28,12 +27,7 @@ function reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function existsCached(path) {
|
function existsCached(path) {
|
||||||
var exists = existsCache[path];
|
return lassoCachingFS.existsSync(path);
|
||||||
if (exists === undefined) {
|
|
||||||
exists = fs.existsSync(path);
|
|
||||||
existsCache[path] = exists;
|
|
||||||
}
|
|
||||||
return exists;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getModuleRootPackage(dirname) {
|
function getModuleRootPackage(dirname) {
|
||||||
@ -105,17 +99,23 @@ function find(dirname, registeredTaglibs) {
|
|||||||
while(true) {
|
while(true) {
|
||||||
if(!excludedDirs[curDirname]) {
|
if(!excludedDirs[curDirname]) {
|
||||||
let taglibPath = nodePath.join(curDirname, 'marko.json');
|
let taglibPath = nodePath.join(curDirname, 'marko.json');
|
||||||
|
let taglib;
|
||||||
|
|
||||||
if (existsCached(taglibPath)) {
|
if (existsCached(taglibPath)) {
|
||||||
let taglib = taglibLoader.load(taglibPath);
|
taglib = taglibLoader.load(taglibPath);
|
||||||
helper.addTaglib(taglib);
|
helper.addTaglib(taglib);
|
||||||
} else {
|
}
|
||||||
let componentPath = nodePath.join(curDirname, 'components');
|
|
||||||
if (existsCached(componentPath) && !excludedDirs[componentPath] && !helper.alreadyAdded(componentPath)) {
|
if (!taglib || taglib.tagsDir === undefined) {
|
||||||
let taglib = new Taglib(componentPath);
|
let componentsPath = nodePath.join(curDirname, 'components');
|
||||||
scanTagsDir(componentPath, nodePath.dirname(componentPath), './components', taglib, new DependencyChain([componentPath]));
|
|
||||||
|
if (existsCached(componentsPath) && !excludedDirs[componentsPath] && !helper.alreadyAdded(componentsPath)) {
|
||||||
|
let taglib = new Taglib(componentsPath);
|
||||||
|
scanTagsDir(componentsPath, nodePath.dirname(componentsPath), './components', taglib, new DependencyChain([componentsPath]));
|
||||||
helper.addTaglib(taglib);
|
helper.addTaglib(taglib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curDirname === rootDirname) {
|
if (curDirname === rootDirname) {
|
||||||
@ -150,7 +150,7 @@ function find(dirname, registeredTaglibs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearCache() {
|
function clearCache() {
|
||||||
existsCache = {};
|
lassoCachingFS.clearCaches();
|
||||||
findCache = {};
|
findCache = {};
|
||||||
taglibsForNodeModulesDirCache = {};
|
taglibsForNodeModulesDirCache = {};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,27 +12,33 @@ function createCustomTagNodeFactory(tagDef) {
|
|||||||
class Tag{
|
class Tag{
|
||||||
constructor() {
|
constructor() {
|
||||||
ok(arguments.length === 0);
|
ok(arguments.length === 0);
|
||||||
this.taglibId = null;
|
|
||||||
this.taglibPath = null;
|
|
||||||
this.name = undefined;
|
|
||||||
this.renderer = null;
|
|
||||||
this.codeGeneratorModulePath = null;
|
|
||||||
this.nodeFactoryPath = null;
|
|
||||||
this.template = null;
|
|
||||||
this.attributes = {};
|
this.attributes = {};
|
||||||
this.transformers = {};
|
this.transformers = {};
|
||||||
this.nestedVariables = null;
|
|
||||||
this.importedVariables = null;
|
|
||||||
this.patternAttributes = [];
|
this.patternAttributes = [];
|
||||||
this.bodyFunction = null;
|
|
||||||
this.nestedTags = null;
|
// NOTE: We don't set this properties since
|
||||||
this.isRepeated = null;
|
// it breaks merging of tags when the same
|
||||||
this.isNestedTag = false;
|
// tag is declared at multiple levels
|
||||||
this.parentTagName = null;
|
|
||||||
this.openTagOnly = null;
|
// this.taglibId = null;
|
||||||
this.body = null;
|
// this.taglibPath = null;
|
||||||
this.type = null; // Only applicable for nested tags
|
// this.name = undefined;
|
||||||
this._nodeFactory = undefined;
|
// this.renderer = null;
|
||||||
|
// this.codeGeneratorModulePath = null;
|
||||||
|
// this.nodeFactoryPath = null;
|
||||||
|
// this.template = null;
|
||||||
|
// this.nestedVariables = null;
|
||||||
|
// this.importedVariables = null;
|
||||||
|
// this.bodyFunction = null;
|
||||||
|
// this.nestedTags = null;
|
||||||
|
// this.isRepeated = null;
|
||||||
|
// this.isNestedTag = false;
|
||||||
|
// this.parentTagName = null;
|
||||||
|
// this.openTagOnly = null;
|
||||||
|
// this.body = null;
|
||||||
|
// this.type = null; // Only applicable for nested tags
|
||||||
|
// this._nodeFactory = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
forEachVariable(callback, thisObj) {
|
forEachVariable(callback, thisObj) {
|
||||||
|
|||||||
@ -188,6 +188,9 @@ class TaglibLoader {
|
|||||||
var path = this.filePath;
|
var path = this.filePath;
|
||||||
var dirname = this.dirname;
|
var dirname = this.dirname;
|
||||||
|
|
||||||
|
taglib.tagsDir = dir;
|
||||||
|
|
||||||
|
if (dir != null) {
|
||||||
if (Array.isArray(dir)) {
|
if (Array.isArray(dir)) {
|
||||||
for (var i = 0; i < dir.length; i++) {
|
for (var i = 0; i < dir.length; i++) {
|
||||||
scanTagsDir(path, dirname, dir[i], taglib, this.dependencyChain.append(`tags-dir[${i}]`));
|
scanTagsDir(path, dirname, dir[i], taglib, this.dependencyChain.append(`tags-dir[${i}]`));
|
||||||
@ -196,6 +199,7 @@ class TaglibLoader {
|
|||||||
scanTagsDir(path, dirname, dir, taglib, this.dependencyChain.append(`tags-dir`));
|
scanTagsDir(path, dirname, dir, taglib, this.dependencyChain.append(`tags-dir`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
taglibImports(imports) {
|
taglibImports(imports) {
|
||||||
if (!resolveFrom) {
|
if (!resolveFrom) {
|
||||||
|
|||||||
@ -61,6 +61,7 @@
|
|||||||
"events-light": "^1.0.0",
|
"events-light": "^1.0.0",
|
||||||
"he": "^1.1.0",
|
"he": "^1.1.0",
|
||||||
"htmljs-parser": "^2.3.0",
|
"htmljs-parser": "^2.3.0",
|
||||||
|
"lasso-caching-fs": "^1.0.1",
|
||||||
"lasso-modules-client": "^2.0.3",
|
"lasso-modules-client": "^2.0.3",
|
||||||
"lasso-package-root": "^1.0.0",
|
"lasso-package-root": "^1.0.0",
|
||||||
"listener-tracker": "^2.0.0",
|
"listener-tracker": "^2.0.0",
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
<div>test-hello</div>
|
||||||
3
test/autotests/render/tags-dir-null/marko.json
Normal file
3
test/autotests/render/tags-dir-null/marko.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"tags-dir": null
|
||||||
|
}
|
||||||
1
test/autotests/render/tags-dir-null/template.marko
Normal file
1
test/autotests/render/tags-dir-null/template.marko
Normal file
@ -0,0 +1 @@
|
|||||||
|
<test-hello/>
|
||||||
11
test/autotests/render/tags-dir-null/test.js
Normal file
11
test/autotests/render/tags-dir-null/test.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
var expect = require('chai').expect;
|
||||||
|
|
||||||
|
exports.templateData = {};
|
||||||
|
|
||||||
|
exports.checkError = function(e) {
|
||||||
|
//includes the tag it broke on
|
||||||
|
expect(e.message).to.contain('Unrecognized tag: test-hello');
|
||||||
|
|
||||||
|
//includes the line number of the template
|
||||||
|
expect(e.message).to.contain('template.marko:1:0');
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user