wooorm / refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Can we change global to globalThis?

xiaoxiangmoe opened this issue · comments

var defined = 'Prism' in global

In browsers we have no global, but we have globalThis both in browsers and nodejs

commented

Did you run into an error?

Yes! I'm using @angular/cli which using webpack as bundler.
image
image

commented

Hmm. Do you know if angular/cli is using webpack 5 now?

This line has been in there since the beginning, millions of users have used it just fine, so I’m assuming bundlers have always added it, but also know that webpack 5 changed some similar things.

No, angular/cli use webpack 4. Maybe we should support webpack 5, also.

commented

In that case, I’m assuming this still works fine in webpack 5 (because that’s been out a bit and nobody else raised an issue for it), but that angular/cli is the root problem.

Regardless, I’d appreciate a PR!

commented

Oh btw, sorry I forgot: I’m not sure globalThis is a good idea. As it doesn’t work everywhere, and that could be a breaking change.

I think we’re already getting the global scope somewhere else in the code. Perhaps use that?

refractor/core.js

Lines 9 to 14 in 0e49fc3

var ctx =
typeof window === 'undefined'
? typeof self === 'undefined'
? {}
: self
: window

Do you mean we should use ctx

commented

I think that’d do the trick yeah. But maybe that’d also need to support Node’s global?