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

Fixes #3533 #3544

Merged
merged 2 commits into from
Jul 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/less/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ module.exports = function(grunt) {
// Handle async / await in Rollup build for tests
// Remove this when Node 6 is no longer supported for the build/test process
const nodeVersion = semver.major(process.versions.node);
const tsNodeRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
let scriptRuntime = 'node';
if (nodeVersion < 8) {
scriptRuntime = path.resolve(path.join('node_modules', '.bin', 'ts-node'));
scriptRuntime = tsNodeRuntime;
}

// Project configuration.
Expand Down Expand Up @@ -228,7 +229,10 @@ module.exports = function(grunt) {
command: scriptRuntime + " build/rollup.js --browser --out=./tmp/browser/less.min.js"
},
test: {
command: "node test/index.js"
command: [
tsNodeRuntime + " test/test-es6.ts",
"node test/index.js"
].join(' && ')
},
generatebrowser: {
command: 'node test/browser/generator/generate.js'
Expand Down
9 changes: 9 additions & 0 deletions packages/less/src/less/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,14 @@ export default (environment, fileManagers) => {
}
}

/**
* Some of the functions assume a `this` context of the API object,
* which causes it to fail when wrapped for ES6 imports.
*
* An assumed `this` should be removed in the future.
*/
initial.parse = initial.parse.bind(api);
initial.render = initial.render.bind(api);

return api;
};
17 changes: 17 additions & 0 deletions packages/less/test/test-es6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://github.com/less/less.js/issues/3533
console.log('Testing ES6 imports...')

import less from '..';
let lessRender = less.render;

// then I call lessRender on something
let y = lessRender(`
body {
a: 1;
b: 2;
c: 30;
d: 4;
}`, {sourceMap: {}}, function(error, output) {
if (error)
console.error(error)
})