Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert 2.3.1 #93

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 6 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,7 @@ const { format } = require('node:util')
function processWarning () {
const codes = {}
const emitted = new Map()

/**
* @typedef {number} STATE_CONSTANT
*/

/**
* @private
* @typdef {object} EMISSION_STATES
* @property {STATE_CONSTANT} UNLIMITED_INITIAL Indicates that the warning
* is to be issued an unlimited number of times but has not yet been
* emitted.
* @property {STATE_CONSTANT} UNLIMITED_ONGOING Indicates that the warning
* is to be issued an unlimited number of times and has been emitted at least
* once.
* @property {STATE_CONSTANT} LIMITED_INITIAL Indicates that the warning
* is to be issued only once but has not yet been emitted.
* @property {STATE_CONSTANT} LIMITED_FINAL Indicates that the warning
* is to be issued only once and has already been emitted.
*/
const STATES = {
UNLIMITED_INITIAL: 0,
UNLIMITED_ONGOING: -1,
LIMITED_INITIAL: 1,
LIMITED_FINAL: 2
}
const opts = Object.create(null)

/**
* Builds a new {@link ProcessWarning} and adds it to the
Expand Down Expand Up @@ -115,7 +91,8 @@ function processWarning () {
}
}

emitted.set(code, unlimited ? STATES.UNLIMITED_INITIAL : STATES.LIMITED_INITIAL)
Object.assign(opts, { unlimited })
emitted.set(code, unlimited)
codes[code] = buildWarnOpts

return codes[code]
Expand Down Expand Up @@ -160,13 +137,9 @@ function processWarning () {
* @param {*} [c] Possible message interpolation value.
*/
function emit (code, a, b, c) {
const state = emitted.get(code)
if (state === STATES.LIMITED_FINAL) return
if (emitted.get(code) === true && opts.unlimited === false) return
if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`)
emitted.set(
code,
state <= STATES.UNLIMITED_INITIAL ? STATES.UNLIMITED_ONGOING : STATES.LIMITED_FINAL
)
emitted.set(code, true)

const warning = codes[code](a, b, c)
process.emitWarning(warning.message, warning.name, warning.code)
Expand All @@ -176,12 +149,7 @@ function processWarning () {
create,
createDeprecation,
emit,
emitted: {
get (code) {
const state = emitted.get(code)
return state === STATES.UNLIMITED_ONGOING || state === STATES.LIMITED_FINAL
}
}
emitted
}
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"benchmark": "node benchmarks/warn.js",
"test": "npm run test:unit && npm run test:jest && npm run test:typescript",
"test:jest": "jest jest.test.js",
"test:unit": "tap",
Expand Down
2 changes: 1 addition & 1 deletion test/emit-once-only.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const test = require('tap').test
const build = require('..')

test('emit should emit a given code only once', t => {
Expand Down
26 changes: 0 additions & 26 deletions test/issue-88.test.js

This file was deleted.

Loading