Skip to content

Commit

Permalink
fix: super calls (#2843)
Browse files Browse the repository at this point in the history
* fix super call in object.js

the super.operate.call syntax doesn't pass in the `this` argument.

The code before the classes #2813 PR was:

```js
Node.prototype.operate.call(this, op, right)
```

and the code was incorrectly transformed into

```js
super.operate.call(op, right);
```

* directly call super methods

instead of doing `super.method.call(this, ...args)`

* chore: add test cases

* chore: add eos

---------

Co-authored-by: Angelo Verlain <geoangercola@gmail.com>
  • Loading branch information
iChenLei and vixalien committed Nov 18, 2023
1 parent e8f078f commit 49e3266
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/nodes/object.js
Expand Up @@ -127,7 +127,7 @@ module.exports = class Object extends Node {
case '!=':
return this.operate('==', right).negate();
default:
return super.operate.call(op, right);
return super.operate(op, right);
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/visitor/sourcemapper.js
Expand Up @@ -64,7 +64,7 @@ module.exports = class SourceMapper extends Compiler {
*/

compile() {
var css = super.compile.call(this)
var css = super.compile()
, out = this.basename + '.map'
, url = this.normalizePath(this.dest
? join(this.dest, out)
Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = class SourceMapper extends Compiler {
*/

visitLiteral(lit) {
var val = super.visitLiteral.call(this, lit)
var val = super.visitLiteral(lit)
, filename = this.normalizePath(lit.filename)
, indentsRe = /^\s+/
, lines = val.split('\n');
Expand Down
3 changes: 3 additions & 0 deletions test/cases/is.a.obj.operator.css
@@ -0,0 +1,3 @@
body {
padding: 5px;
}
13 changes: 13 additions & 0 deletions test/cases/is.a.obj.operator.styl
@@ -0,0 +1,13 @@
// https://github.com/stylus/stylus/pull/2840#issuecomment-1806769376
IS_A_OBJECT = {
height: 10px
}

add(a, b)
if IS_A_OBJECT is a 'object'
a + b
else
error('is a operator not work as expect')

body
padding s('%spx', add(1, 4))
3 changes: 3 additions & 0 deletions test/cases/regression.2820.css
@@ -0,0 +1,3 @@
.main {
color: #f00;
}
18 changes: 18 additions & 0 deletions test/cases/regression.2820.styl
@@ -0,0 +1,18 @@
// https://github.com/stylus/stylus/issues/2820#issue-1876098425
$JIG_CONFIG = {
color: #f00
}
$jig---config ?= null
if !($jig---config is a 'object')
if jig---config is defined
$jig---config = jig---config
else if $JIG_CONFIG is defined
$jig---config = $JIG_CONFIG
else if JIG_CONFIG is defined
$jig---config = JIG_CONFIG

if !($jig---config is a 'object')
error('jig:globals | jig config is undefined or not a hash')

.main
color: $jig---config.color

0 comments on commit 49e3266

Please sign in to comment.