Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile template using babel #260

Merged
merged 3 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions e2e/__projects__/basic/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@ var _default = {
exports[\\"default\\"] = _default;
;
\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
var vue_1 = require(\\"vue\\");
var _hoisted_1 = { class: \\"hello\\" };
function render(_ctx, _cache) {
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
]));
}

Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
exports.render = render;
//# sourceMappingURL=module.js.map;

var _vue = require(\\"vue\\");

var _hoisted_1 = {
\\"class\\": \\"hello\\"
};

function render(_ctx, _cache) {
return (0, _vue.openBlock)(), (0, _vue.createBlock)(\\"div\\", _hoisted_1, [(0, _vue.createVNode)(\\"h1\\", {
\\"class\\": _ctx.headingClasses
}, (0, _vue.toDisplayString)(_ctx.msg), 3
/* TEXT, CLASS */
)]);
};
;exports.default = {...exports.default, render};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFIQTtBQUtBO0FBUEE7QUFTQTtBQUNBO0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ICAgICAgdGhpcy5pc0NyYXp5ID0gIXRoaXMuaXNDcmF6eVxuICAgIH1cbiAgfVxufVxuPC9zY3JpcHQ+XG4iXX0="
`;
Expand Down Expand Up @@ -80,16 +89,25 @@ var _default = {
exports[\\"default\\"] = _default;
;
\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", { value: true });
var vue_1 = require(\\"vue\\");
var _hoisted_1 = { class: \\"hello\\" };
function render(_ctx, _cache) {
return (vue_1.openBlock(), vue_1.createBlock(\\"div\\", _hoisted_1, [
vue_1.createVNode(\\"h1\\", { class: _ctx.headingClasses }, vue_1.toDisplayString(_ctx.msg), 3 /* TEXT, CLASS */)
]));
}

Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
exports.render = render;
//# sourceMappingURL=module.js.map;

var _vue = require(\\"vue\\");

var _hoisted_1 = {
\\"class\\": \\"hello\\"
};

function render(_ctx, _cache) {
return (0, _vue.openBlock)(), (0, _vue.createBlock)(\\"div\\", _hoisted_1, [(0, _vue.createVNode)(\\"h1\\", {
\\"class\\": _ctx.headingClasses
}, (0, _vue.toDisplayString)(_ctx.msg), 3
/* TEXT, CLASS */
)]);
};
;exports.default = {...exports.default, render};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlNvdXJjZU1hcHNTcmMudnVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBS0E7QUFQQTtBQVNBO0FBQ0E7QUFDQTtBQUNBO0FBRkE7QUFJQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFqQkEiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCB7XG4gIG5hbWU6ICdiYXNpYycsXG4gIGNvbXB1dGVkOiB7XG4gICAgaGVhZGluZ0NsYXNzZXM6IGZ1bmN0aW9uIGhlYWRpbmdDbGFzc2VzKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgcmVkOiB0aGlzLmlzQ3JhenksXG4gICAgICAgIGJsdWU6ICF0aGlzLmlzQ3JhenksXG4gICAgICAgIHNoYWRvdzogdGhpcy5pc0NyYXp5XG4gICAgICB9XG4gICAgfVxuICB9LFxuICBkYXRhOiBmdW5jdGlvbiBkYXRhKCkge1xuICAgIHJldHVybiB7XG4gICAgICBtc2c6ICdXZWxjb21lIHRvIFlvdXIgVnVlLmpzIEFwcCcsXG4gICAgICBpc0NyYXp5OiBmYWxzZVxuICAgIH1cbiAgfSxcbiAgbWV0aG9kczoge1xuICAgIHRvZ2dsZUNsYXNzOiBmdW5jdGlvbiB0b2dnbGVDbGFzcygpIHtcbiAgICAgIHRoaXMuaXNDcmF6eSA9ICF0aGlzLmlzQ3JhenlcbiAgICB9XG4gIH1cbn1cbiJdfQ=="
`;
2 changes: 1 addition & 1 deletion lib/generate-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function generateCode(
}

if (templateResult) {
output += `${templateResult.outputText};\n`
output += `${templateResult.code};\n`
}

if (output.includes('exports.render = render;')) {
Expand Down
22 changes: 6 additions & 16 deletions lib/process.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { transpileModule } = require('typescript')
const { parse, compileTemplate } = require('@vue/compiler-sfc')
const { transform } = require('@babel/core')
const convertSourceMap = require('convert-source-map')
const babelTransformer = require('babel-jest')

Expand All @@ -9,7 +9,6 @@ const coffeescriptTransformer = require('./transformers/coffee')
const _processStyle = require('./process-style')
const processCustomBlocks = require('./process-custom-blocks')
const getVueJestConfig = require('./utils').getVueJestConfig
const getTsJestConfig = require('./utils').getTsJestConfig
const logResultErrors = require('./utils').logResultErrors
const stripInlineSourceMap = require('./utils').stripInlineSourceMap
const getCustomTransformer = require('./utils').getCustomTransformer
Expand Down Expand Up @@ -67,22 +66,13 @@ function processTemplate(template, filename, config) {
preprocessOptions: vueJestConfig[template.lang]
})

// const result = compilerUtils.compileTemplate({
// source: template.content,
// compiler: VueTemplateCompiler,
// filename: filename,
// compilerOptions: {
// optimize: false
// },
// isFunctional: template.attrs.functional,
// preprocessLang: template.lang,
// preprocessOptions: vueJestConfig[template.lang]
// })

logResultErrors(result)

const tsconfig = getTsJestConfig(config)
return transpileModule(result.code, tsconfig)
const babelify = transform(result.code, { filename: 'file.js' })

return {
code: babelify.code
}
}

function processStyle(styles, filename, config) {
Expand Down