Skip to content

Commit

Permalink
fix(translator-default): issue with user defined component var
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jun 10, 2021
1 parent 6afebd2 commit a36cfd1
Show file tree
Hide file tree
Showing 387 changed files with 1,414 additions and 1,390 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,7 @@
class {}

$ const component = "World";

<div key="root">
Hello ${component}
</div>
@@ -0,0 +1,6 @@
var expect = require("chai").expect;

module.exports = function (helpers) {
var component = helpers.mount(require.resolve("./index"), {});
expect(component.getEl("root")).to.exist;
};
11 changes: 10 additions & 1 deletion packages/translator-default/src/index.js
Expand Up @@ -166,6 +166,11 @@ export const translate = {
MarkoScriptlet,
MarkoClass,
MarkoComment,
ReferencedIdentifier(path) {
if (path.node.name === "component" && !path.scope.hasBinding("component")) {
path.replaceWith(path.hub.file._componentInstanceIdentifier);
}
},
Program: {
enter(path) {
const {
Expand All @@ -190,6 +195,10 @@ export const translate = {
}

file._componentDefIdentifier = path.scope.generateUidIdentifier(
"componentDef"
);

file._componentInstanceIdentifier = path.scope.generateUidIdentifier(
"component"
);

Expand Down Expand Up @@ -365,7 +374,7 @@ export const translate = {
t.identifier("input"),
t.identifier("out"),
file._componentDefIdentifier,
t.identifier("component"),
file._componentInstanceIdentifier,
t.identifier("state")
],
renderBlock.node
Expand Down
3 changes: 1 addition & 2 deletions packages/translator-default/src/placeholder/index[vdom].js
@@ -1,4 +1,3 @@
import { types as t } from "@marko/compiler";
import write from "../util/vdom-out-write";
import withPreviousLocation from "../util/with-previous-location";

Expand All @@ -13,7 +12,7 @@ export default function (path) {
} else {
path.replaceWith(
withPreviousLocation(
write(method, value, t.identifier("component")),
write(method, value, path.hub.file._componentInstanceIdentifier),
node
)
);
Expand Down
Expand Up @@ -152,7 +152,7 @@ export default function (path, isNullable) {
t.memberExpression(t.identifier("out"), t.identifier("bf")),
[
normalizeTemplateString`f_${key}`,
t.identifier("component"),
file._componentInstanceIdentifier,
t.numericLiteral(1)
]
)
Expand Down
7 changes: 5 additions & 2 deletions packages/translator-default/src/tag/native-tag[vdom]/index.js
Expand Up @@ -67,7 +67,7 @@ export function tagArguments(path, isStatic) {
name,
attrsObj,
!key && isStatic ? t.nullLiteral() : key,
isStatic ? t.nullLiteral() : t.identifier("component"),
isStatic ? t.nullLiteral() : file._componentInstanceIdentifier,
isStatic
? t.numericLiteral(body.length)
: body.length
Expand Down Expand Up @@ -173,7 +173,10 @@ export default function (path, isNullable) {
t.expressionStatement(
t.callExpression(
t.memberExpression(t.identifier("out"), t.identifier("bf")),
[normalizeTemplateString`f_${key}`, t.identifier("component")]
[
normalizeTemplateString`f_${key}`,
path.hub.file._componentInstanceIdentifier
]
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/translator-default/src/text/index[vdom].js
Expand Up @@ -11,7 +11,7 @@ export default function (path) {
write(
"t",
t.stringLiteral(decode(node.value)),
t.identifier("component")
path.hub.file._componentInstanceIdentifier
),
node
)
Expand Down
Expand Up @@ -133,7 +133,7 @@ export function optimizeStaticVDOM(path) {
t.variableDeclarator(identifier, state.currentRoot)
]);
file.path.node.body.push(d);
path.replaceWith(write("n", identifier, t.identifier("component")));
path.replaceWith(write("n", identifier, file._componentInstanceIdentifier));
path.skip();
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tag-i
var _default = _marko_template;
exports.default = _default;
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state) {
let _thing = null;

if (x) {
Expand All @@ -33,7 +33,7 @@ _marko_template._ = (0, _renderer.default)(function (input, out, _component, com

(0, _renderTag.default)(_index.default, {
"thing": _thing
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import _customTag from "./components/custom-tag/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag";
import _marko_renderer from "marko/src/runtime/components/renderer";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
let _thing = null;

if (x) {
Expand All @@ -22,7 +22,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,

_marko_tag(_customTag, {
"thing": _thing
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import _customTag from "./components/custom-tag/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag";
import _marko_renderer from "marko/dist/runtime/components/renderer";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
let _thing = null;

if (x) {
Expand All @@ -22,7 +22,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,

_marko_tag(_customTag, {
"thing": _thing
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true
Expand Down
Expand Up @@ -12,21 +12,21 @@ import { r as _marko_registerComponent } from "marko/src/runtime/components/regi
_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
let _thing = null;

if (x) {
_thing = {
"x": 1,
"renderBody": out => {
out.t("Hello", component);
out.t("Hello", _component);
}
};
}

_marko_tag(_customTag, {
"thing": _thing
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -12,21 +12,21 @@ import { r as _marko_registerComponent } from "marko/dist/runtime/components/reg
_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
let _thing = null;

if (x) {
_thing = {
"x": 1,
"renderBody": out => {
out.t("Hello", component);
out.t("Hello", _component);
}
};
}

_marko_tag(_customTag, {
"thing": _thing
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true
Expand Down
Expand Up @@ -19,7 +19,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tags-
var _default = _marko_template;
exports.default = _default;
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _component, component, state) {
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state) {
const _items = [];

for (const a in b) {
Expand All @@ -31,7 +31,7 @@ _marko_template._ = (0, _renderer.default)(function (input, out, _component, com
(0, _renderTag.default)(_index.default, {
"items": _items,
"other": {}
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag";
import _marko_renderer from "marko/src/runtime/components/renderer";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
const _items = [];

for (const a in b) {
Expand All @@ -20,7 +20,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,
_marko_tag(_hello, {
"items": _items,
"other": {}
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag";
import _marko_renderer from "marko/dist/runtime/components/renderer";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
const _items = [];

for (const a in b) {
Expand All @@ -20,7 +20,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,
_marko_tag(_hello, {
"items": _items,
"other": {}
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { r as _marko_registerComponent } from "marko/src/runtime/components/regi
_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
const _items = [];

for (const a in b) {
Expand All @@ -24,7 +24,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,
_marko_tag(_hello, {
"items": _items,
"other": {}
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true,
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { r as _marko_registerComponent } from "marko/dist/runtime/components/reg
_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _component, component, state) {
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
const _items = [];

for (const a in b) {
Expand All @@ -24,7 +24,7 @@ _marko_template._ = _marko_renderer(function (input, out, _component, component,
_marko_tag(_hello, {
"items": _items,
"other": {}
}, out, _component, "0");
}, out, _componentDef, "0");
}, {
t: _marko_componentType,
i: true
Expand Down

0 comments on commit a36cfd1

Please sign in to comment.