Skip to content

Use transpileModule for TS and transform for babel conditionally #264

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

Merged
merged 2 commits into from
Aug 9, 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: 18 additions & 36 deletions e2e/__projects__/basic/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,16 @@ var _default = {
exports[\\"default\\"] = _default;
;
\\"use strict\\";

Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
exports.render = render;

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

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

Object.defineProperty(exports, \\"__esModule\\", { value: true });
var vue_1 = 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 */
)]);
};
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 */)
]));
}
exports.render = render;
;
;exports.default = {...exports.default, render};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFIQTtBQUtBO0FBUEE7QUFTQTtBQUNBO0FBQ0E7QUF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cy5pc0NyYXp5ID0gIXRoaXMuaXNDcmF6eVxuICAgIH1cbiAgfVxufVxuPC9zY3JpcHQ+XG4iXX0="
`;
Expand Down Expand Up @@ -89,25 +80,16 @@ var _default = {
exports[\\"default\\"] = _default;
;
\\"use strict\\";

Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
exports.render = render;

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

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

Object.defineProperty(exports, \\"__esModule\\", { value: true });
var vue_1 = 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 */
)]);
};
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 */)
]));
}
exports.render = render;
;
;exports.default = {...exports.default, render};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlNvdXJjZU1hcHNTcmMudnVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBS0E7QUFQQTtBQVNBO0FBQ0E7QUFDQTtBQUNBO0FBRkE7QUFJQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFqQkEiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCB7XG4gIG5hbWU6ICdiYXNpYycsXG4gIGNvbXB1dGVkOiB7XG4gICAgaGVhZGluZ0NsYXNzZXM6IGZ1bmN0aW9uIGhlYWRpbmdDbGFzc2VzKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgcmVkOiB0aGlzLmlzQ3JhenksXG4gICAgICAgIGJsdWU6ICF0aGlzLmlzQ3JhenksXG4gICAgICAgIHNoYWRvdzogdGhpcy5pc0NyYXp5XG4gICAgICB9XG4gICAgfVxuICB9LFxuICBkYXRhOiBmdW5jdGlvbiBkYXRhKCkge1xuICAgIHJldHVybiB7XG4gICAgICBtc2c6ICdXZWxjb21lIHRvIFlvdXIgVnVlLmpzIEFwcCcsXG4gICAgICBpc0NyYXp5OiBmYWxzZVxuICAgIH1cbiAgfSxcbiAgbWV0aG9kczoge1xuICAgIHRvZ2dsZUNsYXNzOiBmdW5jdGlvbiB0b2dnbGVDbGFzcygpIHtcbiAgICAgIHRoaXMuaXNDcmF6eSA9ICF0aGlzLmlzQ3JhenlcbiAgICB9XG4gIH1cbn1cbiJdfQ=="
`;
17 changes: 14 additions & 3 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const { parse, compileTemplate } = require('@vue/compiler-sfc')
const { transform } = require('@babel/core')
const convertSourceMap = require('convert-source-map')
const babelTransformer = require('babel-jest')
const { transpileModule } = require('typescript')

const generateSourceMap = require('./generate-source-map')
const typescriptTransformer = require('./transformers/typescript')
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 @@ -68,10 +70,19 @@ function processTemplate(template, filename, config) {

logResultErrors(result)

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

return {
code: babelify.code
if (tsconfig) {
// they are using TypeScript.
const { outputText } = transpileModule(result.code, { tsconfig })
return { code: outputText }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a combination of ts and Babel, I think you should do transform twice, once with typescript and once with Babel. Should it be like that ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I am not sure in this particular case it makes any difference. Not we are transforming the code generated by the @vue/sfc-compiler, not an actual human, so I am not sure we need to care about polyfills. I could be wrong.

} else {
// babel
const babelify = transform(result.code, { filename: 'file.js' })

return {
code: babelify.code
}
}
}

Expand Down