mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
parent
f74f1a6557
commit
b6443ea1f0
@ -232,6 +232,22 @@ class CompileContext extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
setMigrationFlag(name) {
|
||||
var el = this.migrationFlagEl;
|
||||
|
||||
if (!el.hasAttribute(name)) {
|
||||
el.addAttribute({ name });
|
||||
}
|
||||
}
|
||||
|
||||
get migrationFlagEl() {
|
||||
if (!this._mfe) {
|
||||
this._mfe = this.builder.htmlElement("marko-migration-flags");
|
||||
this.root.prependChild(this._mfe);
|
||||
}
|
||||
return this._mfe;
|
||||
}
|
||||
|
||||
pushData(key, data) {
|
||||
var dataStack = this._dataStacks[key];
|
||||
if (!dataStack) {
|
||||
|
||||
@ -99,6 +99,14 @@ class Normalizer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (elNode.tagName === "marko-migration-flags") {
|
||||
elNode.attributes.forEach(attr => {
|
||||
context.setFlag(attr.name);
|
||||
});
|
||||
elNode.detach();
|
||||
return;
|
||||
}
|
||||
|
||||
var newNode = this.context.createNodeForEl({
|
||||
tagName: elNode.rawTagNameExpression
|
||||
? builder.parseExpression(elNode.rawTagNameExpression)
|
||||
|
||||
@ -18,10 +18,7 @@ module.exports = function transform(el, context) {
|
||||
|
||||
if (el.type === "TemplateRoot") {
|
||||
transformHelper.handleRootNodes();
|
||||
if (
|
||||
!context.isFlagSet("hasLegacyWidgetBind") &&
|
||||
context.isFlagSet("hasLegacyWidgetAttr")
|
||||
) {
|
||||
if (context.isFlagSet("legacyWidgetAttrsWithoutBind")) {
|
||||
let builder = context.builder;
|
||||
let getWidgetFromOut = context.helper("getWidgetFromOut");
|
||||
el.prependChild(
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const addIdScopedAttr = require("../util/addIdScopedAttr");
|
||||
const findBoundParent = require("../util/findBoundParent");
|
||||
|
||||
module.exports = function migrate(el, context) {
|
||||
if (
|
||||
@ -15,9 +16,16 @@ module.exports = function migrate(el, context) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.deprecate(
|
||||
`The "w-for", "for-key" and "for-ref" attributes are deprecated. Please use "for:scoped" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
if (name === "w-for" && !findBoundParent(el)) {
|
||||
context.deprecate(
|
||||
`Using "w-for" in a template without a "w-bind" is deprecated. The "${name}" attribute is also deprecated. Please use "for:scoped" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
context.setMigrationFlag("legacyWidgetAttrsWithoutBind");
|
||||
} else {
|
||||
context.deprecate(
|
||||
`The "${name}" attribute is deprecated. Please use "for:scoped" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
}
|
||||
|
||||
if (el.hasAttribute("for:scoped")) {
|
||||
context.addError(
|
||||
|
||||
@ -1,12 +1,21 @@
|
||||
const findBoundParent = require("../util/findBoundParent");
|
||||
|
||||
module.exports = function migrate(el, context) {
|
||||
const attr = el.getAttribute("w-id");
|
||||
if (!attr) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.deprecate(
|
||||
`The "w-id" attribute is deprecated. Please use "key" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
if (findBoundParent(el)) {
|
||||
context.deprecate(
|
||||
`The "w-id" attribute is deprecated. Please use "key" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
} else {
|
||||
context.deprecate(
|
||||
`Using "w-id" in a template without a "w-bind" is deprecated. The "w-id" attribute is also deprecated. Please use "key" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
context.setMigrationFlag("legacyWidgetAttrsWithoutBind");
|
||||
}
|
||||
|
||||
el.setAttributeValue("key", attr.value);
|
||||
const isHTML = el.tagDef && el.tagDef.html;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const printJS = require("../util/printJS");
|
||||
const findBoundParent = require("../util/findBoundParent");
|
||||
|
||||
module.exports = function migrate(el, context) {
|
||||
el.forEachAttribute(attr => {
|
||||
@ -7,9 +8,16 @@ module.exports = function migrate(el, context) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.deprecate(
|
||||
`The "w-on*" attributes are deprecated. Please use "on*()" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
if (findBoundParent(el)) {
|
||||
context.deprecate(
|
||||
`The "w-on*" attributes are deprecated. Please use "on*()" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
} else {
|
||||
context.deprecate(
|
||||
`Using "w-on*" in a template without a "w-bind" is deprecated. The "w-on*" attributes are also deprecated. Please use "on*()" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
context.setMigrationFlag("legacyWidgetAttrsWithoutBind");
|
||||
}
|
||||
|
||||
name = name.substring("w-on".length);
|
||||
if (name.startsWith("-")) name = name.substring("-".length);
|
||||
|
||||
7
src/taglibs/migrate/util/findBoundParent.js
Normal file
7
src/taglibs/migrate/util/findBoundParent.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = function findBoundParent(el) {
|
||||
if (el.type === "HtmlElement" && el.getAttribute("w-bind")) {
|
||||
return el;
|
||||
} else if (el.parentNode) {
|
||||
return findBoundParent(el.parentNode);
|
||||
}
|
||||
};
|
||||
@ -5,12 +5,17 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
|
||||
components_helpers = require("marko/src/components/helpers"),
|
||||
marko_renderer = components_helpers.r,
|
||||
marko_defineComponent = components_helpers.c,
|
||||
marko_getWidgetFromOut = require("marko/src/components/legacy/helper-getWidgetFromOut"),
|
||||
marko_helpers = require("marko/src/runtime/html/helpers"),
|
||||
marko_dynamicTag = marko_helpers.d;
|
||||
|
||||
function render(input, out, __component, component, state) {
|
||||
var data = input;
|
||||
|
||||
var widget = marko_getWidgetFromOut(out),
|
||||
__component = widget,
|
||||
component = __component._c;
|
||||
|
||||
marko_dynamicTag(input, {
|
||||
x: 1
|
||||
}, out, __component, "hi");
|
||||
|
||||
@ -12,5 +12,3 @@ module.exports = function(helpers) {
|
||||
|
||||
expect(window.transitiveHandled).to.eql(true);
|
||||
};
|
||||
|
||||
module.exports.fails = "Issue #1219";
|
||||
|
||||
@ -7,5 +7,3 @@ module.exports = function(helpers) {
|
||||
|
||||
expect(el.tagName).to.eql("BUTTON");
|
||||
};
|
||||
|
||||
module.exports.fails = "Issue #1219";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<!-- test/migrate/fixtures/w-for/template.marko -->
|
||||
|
||||
<marko-migration-flags legacyWidgetAttrsWithoutBind/>
|
||||
<input key="a" id:scoped="a"/>
|
||||
<label for:scoped="a"/>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<!-- test/migrate/fixtures/w-id/template.marko -->
|
||||
|
||||
<marko-migration-flags legacyWidgetAttrsWithoutBind/>
|
||||
<div key="a" id:scoped="a"/>
|
||||
<div key="b" id:scoped="b"/>
|
||||
<test key="c"/>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<!-- test/migrate/fixtures/w-on/template.marko -->
|
||||
|
||||
<marko-migration-flags legacyWidgetAttrsWithoutBind/>
|
||||
<div onClick("handleClick")>
|
||||
<input onChange("handleChange")/>
|
||||
Hello World
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<!-- test/migrate/fixtures/widget-el-id-scoped/template.marko -->
|
||||
|
||||
<marko-migration-flags legacyWidgetAttrsWithoutBind/>
|
||||
<label for:scoped="thing"/>
|
||||
<input key="thing" id:scoped="thing"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user