paiq / blackcoffee

CoffeeScript + hygienic macros
MIT License
105 stars 9 forks source link

helpers.scripts and helpers.filenames are only expanding in the whole modules's lifetime #12

Open leonidborisenko opened 10 years ago

leonidborisenko commented 10 years ago

helpers.scripts and helpers.filenames aren't cleared anywhere in code.

This is not a problem for CLI users, but it has some consequences for API users.

When I use BlackCoffee inside Gruntfile with require('blackcoffee').compile(...), BlackCoffee's module is cached and helpers.scripts/helpers.filenames are expanding and expanding with every processed file. For example, source map generator uses these variables and gets redundant information starting from second processed file:

    v3 =
      version:    3
      file:       options.generatedFile or ''
      sourceRoot: options.sourceRoot or ''
      sources:    helpers.filenames || []
      names:      []
      mappings:   buffer

    if options.inline
        v3.sourcesContent = helpers.scripts || []

I think it's not the only possible edge case.with current implementation. Right now I manually clear these variables before every compile invocation. Would there be any other solution?

vanviegen commented 10 years ago

You're right, those global arrays are rather ugly and may lead to this sort of problems when you're using the API. Your work-around is the best quick fix I could think of. Ideally, we'd want to track source information all the way through the lexer and parser data structures, but that would be quite a big patch I imagine.

I'll keep this issue open, in the hope of resolving it some day...