-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
705598e
commit 33b1d0d
Showing
18 changed files
with
2,419 additions
and
1,323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@marko/compat-utils": patch | ||
"@marko/compat-v4": patch | ||
--- | ||
|
||
Migrate tags with arguments to regular attributes or spreads. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { types as t } from "@marko/compiler"; | ||
import { diagnosticDeprecate } from "@marko/babel-utils"; | ||
import { | ||
exprToAttrs, | ||
getTagFile, | ||
isCoreOrMigrateTag, | ||
} from "@marko/compat-utils"; | ||
|
||
export default { | ||
MarkoTag(tag) { | ||
const args = tag.node.arguments; | ||
if (!args || isCoreOrMigrateTag(tag) || !getTagFile(tag)) { | ||
return; | ||
} | ||
|
||
diagnosticDeprecate(tag, { | ||
label: | ||
"Tag arguments have been deprecated. Instead use regular attributes, or spread attributes.", | ||
fix() { | ||
const attrs: t.MarkoTag["attributes"] = []; | ||
for (const arg of args) { | ||
if (arg.type === "SpreadElement") { | ||
attrs.push(t.markoSpreadAttribute(arg.argument)); | ||
continue; | ||
} | ||
|
||
for (const attr of exprToAttrs(arg)) { | ||
attrs.push(attr); | ||
} | ||
} | ||
|
||
tag.node.arguments = null; | ||
tag.node.attributes = attrs.concat(tag.node.attributes); | ||
}, | ||
}); | ||
}, | ||
} satisfies t.Visitor; |
1 change: 1 addition & 0 deletions
1
.../fixtures-class/tag-arguments/__snapshots__/auto-migrate.expected/components/my-tag.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${JSON.stringify(input)} |
2 changes: 2 additions & 0 deletions
2
tests/fixtures-class/tag-arguments/__snapshots__/auto-migrate.expected/template.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<my-tag x=1/> | ||
<my-tag x=1 y=2 x=3/> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures-class/tag-arguments/__snapshots__/dom.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Render {"attrs":{"data-foo":"bar","data-bar":"baz"}} | ||
```html | ||
{"x":1}{"x":3,"y":2} | ||
``` |
17 changes: 17 additions & 0 deletions
17
tests/fixtures-class/tag-arguments/__snapshots__/dom.expected/components/my-tag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { t as _t } from "marko/src/runtime/vdom/index.js"; | ||
const _marko_componentType = "<fixture-dir>/components/my-tag.marko", | ||
_marko_template = _t(_marko_componentType); | ||
export default _marko_template; | ||
import _marko_renderer from "marko/src/runtime/components/renderer.js"; | ||
import { r as _marko_registerComponent } from "marko/src/runtime/components/registry"; | ||
_marko_registerComponent(_marko_componentType, () => _marko_template); | ||
const _marko_component = {}; | ||
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) { | ||
out.t(JSON.stringify(input), _component); | ||
}, { | ||
t: _marko_componentType, | ||
i: true, | ||
d: true | ||
}, _marko_component); | ||
import _marko_defineComponent from "marko/src/runtime/components/defineComponent.js"; | ||
_marko_template.Component = _marko_defineComponent(_marko_component, _marko_template._); |
26 changes: 26 additions & 0 deletions
26
tests/fixtures-class/tag-arguments/__snapshots__/dom.expected/template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { t as _t } from "marko/src/runtime/vdom/index.js"; | ||
const _marko_componentType = "<fixture-dir>/template.marko", | ||
_marko_template = _t(_marko_componentType); | ||
export default _marko_template; | ||
import _myTag from "./components/my-tag.marko"; | ||
import _marko_tag from "marko/src/runtime/helpers/render-tag.js"; | ||
import _marko_renderer from "marko/src/runtime/components/renderer.js"; | ||
import { r as _marko_registerComponent } from "marko/src/runtime/components/registry"; | ||
_marko_registerComponent(_marko_componentType, () => _marko_template); | ||
const _marko_component = {}; | ||
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) { | ||
_marko_tag(_myTag, { | ||
"x": 1 | ||
}, out, _componentDef, "0"); | ||
_marko_tag(_myTag, { | ||
"x": 1, | ||
"y": 2, | ||
"x": 3 | ||
}, out, _componentDef, "1"); | ||
}, { | ||
t: _marko_componentType, | ||
i: true, | ||
d: true | ||
}, _marko_component); | ||
import _marko_defineComponent from "marko/src/runtime/components/defineComponent.js"; | ||
_marko_template.Component = _marko_defineComponent(_marko_component, _marko_template._); |
7 changes: 7 additions & 0 deletions
7
tests/fixtures-class/tag-arguments/__snapshots__/html.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Write | ||
{"x":1}{"x":3,"y":2} | ||
|
||
# Render {"attrs":{"data-foo":"bar","data-bar":"baz"}} | ||
```html | ||
{"x":1}{"x":3,"y":2} | ||
``` |
14 changes: 14 additions & 0 deletions
14
tests/fixtures-class/tag-arguments/__snapshots__/html.expected/components/my-tag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { t as _t } from "marko/src/runtime/html/index.js"; | ||
const _marko_componentType = "<fixture-dir>/components/my-tag.marko", | ||
_marko_template = _t(_marko_componentType); | ||
export default _marko_template; | ||
import { x as _marko_escapeXml } from "marko/src/runtime/html/helpers/escape-xml.js"; | ||
import _marko_renderer from "marko/src/runtime/components/renderer.js"; | ||
const _marko_component = {}; | ||
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) { | ||
out.w(_marko_escapeXml(JSON.stringify(input))); | ||
}, { | ||
t: _marko_componentType, | ||
i: true, | ||
d: true | ||
}, _marko_component); |
22 changes: 22 additions & 0 deletions
22
tests/fixtures-class/tag-arguments/__snapshots__/html.expected/template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { t as _t } from "marko/src/runtime/html/index.js"; | ||
const _marko_componentType = "<fixture-dir>/template.marko", | ||
_marko_template = _t(_marko_componentType); | ||
export default _marko_template; | ||
import _myTag from "./components/my-tag.marko"; | ||
import _marko_tag from "marko/src/runtime/helpers/render-tag.js"; | ||
import _marko_renderer from "marko/src/runtime/components/renderer.js"; | ||
const _marko_component = {}; | ||
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) { | ||
_marko_tag(_myTag, { | ||
"x": 1 | ||
}, out, _componentDef, "0"); | ||
_marko_tag(_myTag, { | ||
"x": 1, | ||
"y": 2, | ||
"x": 3 | ||
}, out, _componentDef, "1"); | ||
}, { | ||
t: _marko_componentType, | ||
i: true, | ||
d: true | ||
}, _marko_component); |
4 changes: 4 additions & 0 deletions
4
tests/fixtures-class/tag-arguments/__snapshots__/hydrate.expected.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Render {"attrs":{"data-foo":"bar","data-bar":"baz"}} | ||
```html | ||
{"x":1}{"x":3,"y":2} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- ${JSON.stringify(input)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<my-tag({ x: 1 })/> | ||
<my-tag({ x: 1 }, { y: 2 }, { x: 3 })/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { FixtureConfig } from "../../main.test"; | ||
|
||
export default { | ||
input: { | ||
attrs: { | ||
"data-foo": "bar", | ||
"data-bar": "baz", | ||
}, | ||
}, | ||
} satisfies FixtureConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters