Skip to content

Commit

Permalink
fix js target affecting css
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 9, 2021
1 parent ba90d1b commit 12178e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/compat/css_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var cssTable = map[CSSFeature]map[Engine][]int{
func UnsupportedCSSFeatures(constraints map[Engine][]int) (unsupported CSSFeature) {
for feature, engines := range cssTable {
for engine, version := range constraints {
if engine == ES {
// Specifying "--target=es2020" shouldn't affect CSS
continue
}
if minVersion, ok := engines[engine]; !ok || isVersionLessThan(version, minVersion) {
unsupported |= feature
}
Expand Down
23 changes: 23 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,29 @@ let transformTests = {
assert.strictEqual(code, `.π:after {\n content: "π";\n}\n`)
},

async cssMinify({ esbuild }) {
const { code } = await esbuild.transform(`div { color: #abcd }`, { loader: 'css', minify: true })
assert.strictEqual(code, `div{color:#abcd}\n`)
},

// Using an "esN" target shouldn't affect CSS
async cssMinifyTargetES6({ esbuild }) {
const { code } = await esbuild.transform(`div { color: #abcd }`, { loader: 'css', minify: true, target: 'es6' })
assert.strictEqual(code, `div{color:#abcd}\n`)
},

// Using an older browser target should affect CSS
async cssMinifyTargetChrome8({ esbuild }) {
const { code } = await esbuild.transform(`div { color: #abcd }`, { loader: 'css', minify: true, target: 'chrome8' })
assert.strictEqual(code, `div{color:rgba(170,187,204,.867)}\n`)
},

// Using a newer browser target shouldn't affect CSS
async cssMinifyTargetChrome80({ esbuild }) {
const { code } = await esbuild.transform(`div { color: #abcd }`, { loader: 'css', minify: true, target: 'chrome80' })
assert.strictEqual(code, `div{color:#abcd}\n`)
},

async cjs_require({ esbuild }) {
const { code } = await esbuild.transform(`const {foo} = require('path')`, {})
assert.strictEqual(code, `const {foo} = require("path");\n`)
Expand Down

0 comments on commit 12178e3

Please sign in to comment.