Skip to content

Commit

Permalink
fix: additional taglib cleanup for website support
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed May 27, 2020
1 parent fb26c87 commit f462d8a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 138 deletions.
13 changes: 6 additions & 7 deletions packages/compiler/src/babel-plugin/index.js
Expand Up @@ -49,20 +49,19 @@ export default (api, options) => {
if (!options._parseOnly) {
nodePath.get("program").scope.crawl(); // Initialize bindings.
const rootMigrators = Object.values(hub.lookup.taglibsById)
.map(taglib => taglib.getMigrator())
.filter(m => m)
.map(m => m.default || m)
.map(m => m(api, options));
.map(it => it.migratorPath)
.filter(Boolean)
.map(it => markoModules.require(it))
.map(it => (it.default || it)(api, options));
nodePath.traverse(
rootMigrators.length
? visitors.merge(rootMigrators.concat(migrate))
: migrate
);
if (!options._migrateOnly) {
const rootTransformers = hub.lookup.merged.transformers
.map(t => markoModules.require(t.path))
.map(t => t.default || t)
.map(t => t(api, options));
.map(it => markoModules.require(it.path))
.map(it => (it.default || it)(api, options));
nodePath.traverse(
rootTransformers.length
? visitors.merge(rootTransformers.concat(transform))
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler/src/babel-plugin/parser.js
Expand Up @@ -294,8 +294,7 @@ export function parse(fileNodePath) {
if (tagDef && tagDef.nodeFactoryPath) {
const module = markoModules.require(tagDef.nodeFactoryPath);
/* istanbul ignore next */
const { default: fn = module } = module;
fn(tag, t);
(module.default || module)(tag, t);
}

currentTag = currentTag.parentPath.parentPath;
Expand Down
31 changes: 1 addition & 30 deletions packages/marko/src/taglib/taglib-loader/Tag.js
Expand Up @@ -2,8 +2,6 @@
var forEachEntry = require("raptor-util/forEachEntry");
var ok = require("assert").ok;
var path = require("path");
var markoModules = require("@marko/compiler/modules");
var complain = require("complain");
var hasOwnProperty = Object.prototype.hasOwnProperty;

class Tag {
Expand All @@ -13,7 +11,6 @@ class Tag {
this.dir = path.dirname(filePath);
}

this.migrators = {};
this.migratorPaths = [];
this.attributes = {};
this.transformers = {};
Expand Down Expand Up @@ -58,29 +55,8 @@ class Tag {
return false;
}

checkDeprecatedAttr(attr) {
attr.filePath = this.filePath;
if (attr.setFlag && attr.setFlag !== "hasComponentEvents") {
complain(`${attr.name} - : set-flag property is deprecated`, {
location: this.filePath
});
}
if (attr.type === "template") {
complain(`${attr.name} - attribute template type is deprecated`, {
location: this.filePath
});
}

if (attr.type === "path") {
complain(`${attr.name} - attribute path type is deprecated`, {
location: this.filePath
});
}
}

addAttribute(attr) {
attr.filePath = this.filePath;
this.checkDeprecatedAttr(attr);

if (attr.pattern) {
this.patternAttributes.push(attr);
Expand Down Expand Up @@ -165,12 +141,7 @@ class Tag {
}

forEachMigrator(callback, thisObj) {
this.migratorPaths
.map(function(path) {
return (this.migrators[path] =
this.migrators[path] || markoModules.require(path));
}, this)
.forEach(callback, thisObj);
this.migratorPaths.forEach(callback, thisObj);
}

toJSON() {
Expand Down
13 changes: 0 additions & 13 deletions packages/marko/src/taglib/taglib-loader/Taglib.js
Expand Up @@ -3,7 +3,6 @@ var forEachEntry = require("raptor-util/forEachEntry");
var ok = require("assert").ok;
var path = require("path");
var loaders = require("./loaders");
var markoModules = require("@marko/compiler/modules");
var hasOwnProperty = Object.prototype.hasOwnProperty;

function handleImport(taglib, importedTaglib) {
Expand Down Expand Up @@ -33,7 +32,6 @@ class Taglib {
this.filePath = this.path /* deprecated */ = this.id = filePath;
this.dirname = path.dirname(this.filePath);
this.tags = {};
this.textTransformers = [];
this.transformers = [];
this.attributes = {};
this.patternAttributes = [];
Expand Down Expand Up @@ -67,13 +65,6 @@ class Taglib {
}
return attribute;
}
getMigrator() {
var path = this.migratorPath;

if (path) {
return (this._migrator = this._migrator || markoModules.require(path));
}
}
addTag(tag) {
ok(arguments.length === 1, "Invalid args");
if (!tag.name) {
Expand All @@ -82,9 +73,6 @@ class Taglib {
this.tags[tag.name] = tag;
tag.taglibId = this.id || this.path;
}
addTextTransformer(transformer) {
this.textTransformers.push(transformer);
}
addTransformer(transformer) {
this.transformers.push(transformer);
}
Expand All @@ -107,7 +95,6 @@ class Taglib {
return {
path: this.path,
tags: this.tags,
textTransformers: this.textTransformers,
attributes: this.attributes,
patternAttributes: this.patternAttributes,
imports: this.imports
Expand Down
28 changes: 0 additions & 28 deletions packages/marko/src/taglib/taglib-loader/Transformer.js
@@ -1,6 +1,5 @@
"use strict";
var nextTransformerId = 0;
var markoModules = require("@marko/compiler/modules");

class Transformer {
constructor() {
Expand All @@ -13,33 +12,6 @@ class Transformer {
this.properties = {};
}

getFunc() {
if (!this.path) {
throw new Error(
"Transformer path not defined for tag transformer (tag=" +
this.tag +
")"
);
}

if (!this._func) {
var transformer = markoModules.require(this.path);

if (typeof transformer === "function") {
if (transformer.prototype.process) {
var Clazz = transformer;
var instance = new Clazz();
instance.id = this.id;
this._func = instance.process.bind(instance);
} else {
this._func = transformer;
}
} else {
this._func = transformer.process || transformer.transform;
}
}
return this._func;
}
toString() {
return "[Taglib.Transformer: " + this.path + "]";
}
Expand Down
30 changes: 0 additions & 30 deletions packages/marko/src/taglib/taglib-loader/loadTaglibFromProps.js
Expand Up @@ -315,36 +315,6 @@ class TaglibLoader {
taglib.migratorPath = path;
}

textTransformer(value) {
// Marko allows a "text-transformer" to be registered. The provided
// text transformer will be called for any static text found in a template.
var taglib = this.taglib;
var dirname = this.dirname;

var transformer = new types.Transformer();

if (typeof value === "string") {
value = {
path: value
};
}

propertyHandlers(
value,
{
path(value) {
var path = resolveFrom(dirname, value);
transformer.path = path;
}
},
this.dependencyChain.append("textTransformer").toString()
);

ok(transformer.path, '"path" is required for transformer');

taglib.addTextTransformer(transformer);
}

/**
* Allows an ID to be explicitly assigned to a taglib.
* The taglib ID is used to prevent the same taglib (even if different versions)
Expand Down
31 changes: 3 additions & 28 deletions packages/marko/src/taglib/taglib-lookup/TaglibLookup.js
Expand Up @@ -21,9 +21,7 @@ function transformerComparator(a, b) {
}

function TAG_COMPARATOR(a, b) {
a = a.name;
b = b.name;
return a.localeCompare(b);
return a.name.localeCompare(b.name);
}

function merge(target, source) {
Expand Down Expand Up @@ -133,7 +131,6 @@ class TaglibLookup {
merge(this.merged, {
tags: taglib.tags,
transformers: taglib.transformers,
textTransformers: taglib.textTransformers,
attributes: taglib.attributes,
patternAttributes: taglib.patternAttributes,
attributeGroups: taglib.attributeGroups || {}
Expand Down Expand Up @@ -322,7 +319,7 @@ class TaglibLookup {

forEachTemplateMigrator(callback, thisObj) {
for (var key in this.taglibsById) {
var migration = this.taglibsById[key].getMigrator();
var migration = this.taglibsById[key].migratorPath;
if (migration) {
callback.call(thisObj, migration);
}
Expand Down Expand Up @@ -396,7 +393,7 @@ class TaglibLookup {
var transformers = [];

function addTransformer(transformer) {
if (!transformer || !transformer.getFunc) {
if (!transformer || !transformer.path) {
throw new Error("Invalid transformer");
}

Expand Down Expand Up @@ -433,28 +430,6 @@ class TaglibLookup {
}
}

getInputFiles() {
if (!this._inputFiles) {
var inputFilesSet = {};

for (var taglibId in this.taglibsById) {
if (hasOwnProperty.call(this.taglibsById, taglibId)) {
var taglibInputFiles = this.taglibsById[taglibId].getInputFiles();
var len = taglibInputFiles.length;
if (len) {
for (var i = 0; i < len; i++) {
inputFilesSet[taglibInputFiles[i]] = true;
}
}
}
}

this._inputFiles = Object.keys(inputFilesSet);
}

return this._inputFiles;
}

toString() {
return "lookup: " + this.getInputFiles().join(", ");
}
Expand Down

0 comments on commit f462d8a

Please sign in to comment.