Skip to content

Passing compiler Functions/Mixins across different compilations should not be allowed #2542

Open
@ntkme

Description

@ntkme

See the following code as an illustration of the issue. On sass this "worked correctly", because callables from other function registries with in the same dart/js VM memory space can be directly accessed and called as functions/mixins are never serialized. However, on sass-embedded this is broken, as only the function id is being passed, which is not a real serialization of the function/mixin content, thus it will refer to a function in the current register even if we passed the function from a different registry.

const sass = require('sass-embedded');
// or
// const sass = require('sass');

const outer = `
  @use 'sass:meta';

  @function foo($n) {@return $n + 1}
  a {b: meta.call(bar(meta.get-function('foo')), 0); }
`

const inner = `
  @use 'sass:meta';

  @function foo($n) {@return $n + 2}
  a {b: meta.call(bar(meta.get-function('foo')), 0); }
`

sass.compileString(outer, {
  functions: {
    'bar($arg)': (args) => {
      const outerFn = args[0]
      console.log(sass.compileString(inner, {
        functions: {
          'bar($arg)': (args) => {
            const innerFn = args[0]
            console.log(outerFn.equals(innerFn))
            return outerFn
          }
        },
      }).css)
      return outerFn
    }
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions