Add `patchStackTrace` export; test that all named exports are detected by Node (#5411)

This commit is contained in:
Geoffrey Booth 2022-04-19 09:58:30 -07:00 committed by GitHub
parent 4f365524d7
commit 6b4f166eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 0 deletions

View File

@ -485,6 +485,7 @@ module.<span class="hljs-built_in">exports</span>.register = CoffeeScript.regist
module.<span class="hljs-built_in">exports</span>.<span class="hljs-built_in">eval</span> = CoffeeScript.<span class="hljs-built_in">eval</span>
module.<span class="hljs-built_in">exports</span>.run = CoffeeScript.run
module.<span class="hljs-built_in">exports</span>.transpile = CoffeeScript.transpile
module.<span class="hljs-built_in">exports</span>.patchStackTrace = CoffeeScript.patchStackTrace
module.<span class="hljs-built_in">exports</span>._compileRawFileContent = CoffeeScript._compileRawFileContent
module.<span class="hljs-built_in">exports</span>._compileFile = CoffeeScript._compileFile</pre></div></div>

View File

@ -31451,6 +31451,36 @@ banner text
].join('\n')
ok new OptionParser(flags).help() is expected
</script>
<script type="text/x-coffeescript" class="test" id="package">
return if window? or testingBrowser?
{EventEmitter} = require 'events'
{join} = require 'path'
{cwd} = require 'process'
{pathToFileURL} = require 'url'
packageEntryPath = join cwd(), 'lib/coffeescript/index.js'
packageEntryUrl = pathToFileURL packageEntryPath
test "the coffeescript package exposes all members as named exports in Node", ->
requiredPackage = require packageEntryPath
requiredKeys = Object.keys requiredPackage
importedPackage = await import(packageEntryUrl)
importedKeys = new Set Object.keys(importedPackage)
# In `command.coffee`, CoffeeScript extends a `new EventEmitter`;
# we want to ignore these additional added keys.
eventEmitterKeys = new Set Object.getOwnPropertyNames(Object.getPrototypeOf(new EventEmitter))
for key in requiredKeys when not eventEmitterKeys.has(key)
# Use `eq` test so that missing keys have their names printed in the error message.
eq (if importedKeys.has(key) then key else undefined), key
</script>
<script type="text/x-coffeescript" class="test" id="parser">
# Parser

View File

@ -208,6 +208,8 @@
module.exports.transpile = CoffeeScript.transpile;
module.exports.patchStackTrace = CoffeeScript.patchStackTrace;
module.exports._compileRawFileContent = CoffeeScript._compileRawFileContent;
module.exports._compileFile = CoffeeScript._compileFile;

View File

@ -155,5 +155,6 @@ module.exports.register = CoffeeScript.register
module.exports.eval = CoffeeScript.eval
module.exports.run = CoffeeScript.run
module.exports.transpile = CoffeeScript.transpile
module.exports.patchStackTrace = CoffeeScript.patchStackTrace
module.exports._compileRawFileContent = CoffeeScript._compileRawFileContent
module.exports._compileFile = CoffeeScript._compileFile

27
test/package.coffee Normal file
View File

@ -0,0 +1,27 @@
return if window? or testingBrowser?
{EventEmitter} = require 'events'
{join} = require 'path'
{cwd} = require 'process'
{pathToFileURL} = require 'url'
packageEntryPath = join cwd(), 'lib/coffeescript/index.js'
packageEntryUrl = pathToFileURL packageEntryPath
test "the coffeescript package exposes all members as named exports in Node", ->
requiredPackage = require packageEntryPath
requiredKeys = Object.keys requiredPackage
importedPackage = await import(packageEntryUrl)
importedKeys = new Set Object.keys(importedPackage)
# In `command.coffee`, CoffeeScript extends a `new EventEmitter`;
# we want to ignore these additional added keys.
eventEmitterKeys = new Set Object.getOwnPropertyNames(Object.getPrototypeOf(new EventEmitter))
for key in requiredKeys when not eventEmitterKeys.has(key)
# Use `eq` test so that missing keys have their names printed in the error message.
eq (if importedKeys.has(key) then key else undefined), key