diff --git a/src/core-tags/components/class-tag-node-factory.js b/src/core-tags/components/class-tag-node-factory.js
new file mode 100644
index 000000000..1978c76b1
--- /dev/null
+++ b/src/core-tags/components/class-tag-node-factory.js
@@ -0,0 +1,6 @@
+module.exports = function nodeFactory(el) {
+ // Previously `class` was a CodeGenerator.
+ // CodeGenerators have their `type` overwritten and some code is relying on that for `class`.
+ el.type = __filename;
+ return el;
+};
diff --git a/src/core-tags/components/class-tag-transformer.js b/src/core-tags/components/class-tag-transformer.js
new file mode 100644
index 000000000..cd48f8e36
--- /dev/null
+++ b/src/core-tags/components/class-tag-transformer.js
@@ -0,0 +1,7 @@
+module.exports = function transformer(el, context) {
+ if (el.parentNode.type !== "TemplateRoot") {
+ context.addError(
+ "class is a static tag and can only be declared at the template root"
+ );
+ }
+};
diff --git a/src/core-tags/components/marko.json b/src/core-tags/components/marko.json
index eec87d836..6613d0941 100644
--- a/src/core-tags/components/marko.json
+++ b/src/core-tags/components/marko.json
@@ -123,5 +123,13 @@
"
": {
"transformer": "./body-transformer.js"
},
+ "": {
+ "node-factory": "./class-tag-node-factory.js",
+ "transformer": {
+ "path": "./class-tag-transformer.js",
+ "priority": -1
+ },
+ "open-tag-only": true
+ },
"transformer": "./components-transformer.js"
}
diff --git a/src/core-tags/core/class-tag.js b/src/core-tags/core/class-tag.js
deleted file mode 100644
index d232b7ee2..000000000
--- a/src/core-tags/core/class-tag.js
+++ /dev/null
@@ -1,9 +0,0 @@
-module.exports = function functionCodeGenerator(el, codegen) {
- if (el.parentNode.type !== "TemplateRoot") {
- codegen.addError(
- "class is a static tag and can only be declared at the template root"
- );
- }
- codegen.addStaticCode(codegen.builder.expression(el.tagString));
- return null;
-};
diff --git a/src/core-tags/core/marko.json b/src/core-tags/core/marko.json
index 56abe3bba..9c0048a09 100644
--- a/src/core-tags/core/marko.json
+++ b/src/core-tags/core/marko.json
@@ -1,8 +1,4 @@
{
- "": {
- "code-generator": "./class-tag",
- "open-tag-only": true
- },
"": {
"node-factory": "./else-tag",
"attributes": {},
diff --git a/src/core-tags/migrate/class-tag.js b/src/core-tags/migrate/class-tag.js
new file mode 100644
index 000000000..750a4fc41
--- /dev/null
+++ b/src/core-tags/migrate/class-tag.js
@@ -0,0 +1,19 @@
+const classNamedRegexp = /^(\s*class\s*)(?!extends)[^\s]+(\s*{)/;
+module.exports = function migrator(el, context) {
+ if (!el.tagString || !classNamedRegexp.test(el.tagString)) {
+ // Check for a named class
+ return;
+ }
+
+ if (el.parentNode.type !== "TemplateRoot") {
+ context.addError(
+ "class is a static tag and can only be declared at the template root"
+ );
+ }
+
+ context.deprecate(
+ "Having a named class at the top level of a file is deprecated. Use `class {...}` without a name instead."
+ );
+
+ el.tagString = el.tagString.replace(classNamedRegexp, "$1$2");
+};
diff --git a/src/core-tags/migrate/marko.json b/src/core-tags/migrate/marko.json
index 3a01b8b5a..7ab7f5d23 100644
--- a/src/core-tags/migrate/marko.json
+++ b/src/core-tags/migrate/marko.json
@@ -217,5 +217,9 @@
"