mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
parent
e73b065360
commit
a030d15018
@ -16,6 +16,7 @@ import {
|
||||
transformJSXSpreadAttribute,
|
||||
transformJSXSpreadChild,
|
||||
transformJSXText,
|
||||
transformText,
|
||||
walksScope,
|
||||
} from './utils';
|
||||
import SlotFlags from './slotFlags';
|
||||
@ -36,7 +37,7 @@ const getJSXAttributeValue = (
|
||||
return transformJSXElement(valuePath, state);
|
||||
}
|
||||
if (valuePath.isStringLiteral()) {
|
||||
return transformJSXText(valuePath);
|
||||
return t.stringLiteral(transformText(valuePath.node.value));
|
||||
}
|
||||
if (valuePath.isJSXExpressionContainer()) {
|
||||
return transformJSXExpressionContainer(valuePath);
|
||||
|
@ -140,8 +140,12 @@ export const getJSXAttributeName = (path: NodePath<t.JSXAttribute>): string => {
|
||||
export const transformJSXText = (
|
||||
path: NodePath<t.JSXText | t.StringLiteral>
|
||||
): t.StringLiteral | null => {
|
||||
const { node } = path;
|
||||
const lines = node.value.split(/\r\n|\n|\r/);
|
||||
const str = transformText(path.node.value);
|
||||
return str !== '' ? t.stringLiteral(str) : null;
|
||||
};
|
||||
|
||||
export const transformText = (text: string) => {
|
||||
const lines = text.split(/\r\n|\n|\r/);
|
||||
|
||||
let lastNonEmptyLine = 0;
|
||||
|
||||
@ -182,7 +186,7 @@ export const transformJSXText = (
|
||||
}
|
||||
}
|
||||
|
||||
return str !== '' ? t.stringLiteral(str) : null;
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -254,6 +254,15 @@ describe('Transform JSX', () => {
|
||||
|
||||
expect(calls).toEqual(expect.arrayContaining([3, 4]));
|
||||
});
|
||||
|
||||
test('empty string', () => {
|
||||
const wrapper = shallowMount({
|
||||
setup() {
|
||||
return () => <h1 title=""></h1>;
|
||||
},
|
||||
});
|
||||
expect(wrapper.html()).toBe('<h1 title=""></h1>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('directive', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user