Skip to content

Commit

Permalink
revert 2.3.1 (#93)
Browse files Browse the repository at this point in the history
* Revert "Use constants instead of magic numbers (#90)"

This reverts commit c56e1e8.

* Revert "fix: avoid global unlimited config (#89)"

This reverts commit d455a6e.
  • Loading branch information
Eomm committed Dec 2, 2023
1 parent b435e64 commit 430106d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 66 deletions.
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.

0 comments on commit 430106d

Please sign in to comment.