padutils: Rename warnWithStack()
to warnDeprecated()
This makes it more legitimate for tests to disable the warnings when testing deprecated functionality.
This commit is contained in:
parent
e4944b8bfa
commit
c4f18a9b3a
2 changed files with 14 additions and 13 deletions
|
@ -253,7 +253,7 @@ class OpIter {
|
||||||
* @returns {OpIter} Operator iterator object.
|
* @returns {OpIter} Operator iterator object.
|
||||||
*/
|
*/
|
||||||
exports.opIterator = (opsStr) => {
|
exports.opIterator = (opsStr) => {
|
||||||
padutils.warnWithStack(
|
padutils.warnDeprecated(
|
||||||
'Changeset.opIterator() is deprecated; use Changeset.deserializeOps() instead');
|
'Changeset.opIterator() is deprecated; use Changeset.deserializeOps() instead');
|
||||||
return new OpIter(opsStr);
|
return new OpIter(opsStr);
|
||||||
};
|
};
|
||||||
|
@ -278,7 +278,7 @@ const clearOp = (op) => {
|
||||||
* @returns {Op}
|
* @returns {Op}
|
||||||
*/
|
*/
|
||||||
exports.newOp = (optOpcode) => {
|
exports.newOp = (optOpcode) => {
|
||||||
padutils.warnWithStack('Changeset.newOp() is deprecated; use the Changeset.Op class instead');
|
padutils.warnDeprecated('Changeset.newOp() is deprecated; use the Changeset.Op class instead');
|
||||||
return new Op(optOpcode);
|
return new Op(optOpcode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -477,8 +477,8 @@ exports.smartOpAssembler = () => {
|
||||||
* attribute key, value pairs.
|
* attribute key, value pairs.
|
||||||
*/
|
*/
|
||||||
const appendOpWithText = (opcode, text, attribs, pool) => {
|
const appendOpWithText = (opcode, text, attribs, pool) => {
|
||||||
padutils.warnWithStack('Changeset.smartOpAssembler().appendOpWithText() is deprecated; ' +
|
padutils.warnDeprecated('Changeset.smartOpAssembler().appendOpWithText() is deprecated; ' +
|
||||||
'use opsFromText() instead.');
|
'use opsFromText() instead.');
|
||||||
for (const op of opsFromText(opcode, text, attribs, pool)) append(op);
|
for (const op of opsFromText(opcode, text, attribs, pool)) append(op);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1647,8 +1647,8 @@ exports.makeAttribution = (text) => {
|
||||||
* @param {Function} func - function to call
|
* @param {Function} func - function to call
|
||||||
*/
|
*/
|
||||||
exports.eachAttribNumber = (cs, func) => {
|
exports.eachAttribNumber = (cs, func) => {
|
||||||
padutils.warnWithStack('Changeset.eachAttribNumber() is deprecated; ' +
|
padutils.warnDeprecated(
|
||||||
'use attributes.decodeAttribString() instead');
|
'Changeset.eachAttribNumber() is deprecated; use attributes.decodeAttribString() instead');
|
||||||
let dollarPos = cs.indexOf('$');
|
let dollarPos = cs.indexOf('$');
|
||||||
if (dollarPos < 0) {
|
if (dollarPos < 0) {
|
||||||
dollarPos = cs.length;
|
dollarPos = cs.length;
|
||||||
|
@ -1801,7 +1801,7 @@ exports.opsFromAText = function* (atext) {
|
||||||
* @param assem - Assembler like SmartOpAssembler TODO add desc
|
* @param assem - Assembler like SmartOpAssembler TODO add desc
|
||||||
*/
|
*/
|
||||||
exports.appendATextToAssembler = (atext, assem) => {
|
exports.appendATextToAssembler = (atext, assem) => {
|
||||||
padutils.warnWithStack(
|
padutils.warnDeprecated(
|
||||||
'Changeset.appendATextToAssembler() is deprecated; use Changeset.opsFromAText() instead');
|
'Changeset.appendATextToAssembler() is deprecated; use Changeset.opsFromAText() instead');
|
||||||
for (const op of exports.opsFromAText(atext)) assem.append(op);
|
for (const op of exports.opsFromAText(atext)) assem.append(op);
|
||||||
};
|
};
|
||||||
|
@ -1854,7 +1854,8 @@ const attribsAttributeValue = (attribs, key, pool) => {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
exports.opAttributeValue = (op, key, pool) => {
|
exports.opAttributeValue = (op, key, pool) => {
|
||||||
padutils.warnWithStack('Changeset.opAttributeValue() is deprecated; use an AttributeMap instead');
|
padutils.warnDeprecated(
|
||||||
|
'Changeset.opAttributeValue() is deprecated; use an AttributeMap instead');
|
||||||
return attribsAttributeValue(op.attribs, key, pool);
|
return attribsAttributeValue(op.attribs, key, pool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1868,8 +1869,8 @@ exports.opAttributeValue = (op, key, pool) => {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
exports.attribsAttributeValue = (attribs, key, pool) => {
|
exports.attribsAttributeValue = (attribs, key, pool) => {
|
||||||
padutils.warnWithStack('Changeset.attribsAttributeValue() is deprecated; ' +
|
padutils.warnDeprecated(
|
||||||
'use an AttributeMap instead');
|
'Changeset.attribsAttributeValue() is deprecated; use an AttributeMap instead');
|
||||||
return attribsAttributeValue(attribs, key, pool);
|
return attribsAttributeValue(attribs, key, pool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1980,7 +1981,7 @@ exports.builder = (oldLen) => {
|
||||||
* @returns {AttributeString}
|
* @returns {AttributeString}
|
||||||
*/
|
*/
|
||||||
exports.makeAttribsString = (opcode, attribs, pool) => {
|
exports.makeAttribsString = (opcode, attribs, pool) => {
|
||||||
padutils.warnWithStack(
|
padutils.warnDeprecated(
|
||||||
'Changeset.makeAttribsString() is deprecated; ' +
|
'Changeset.makeAttribsString() is deprecated; ' +
|
||||||
'use AttributeMap.prototype.toString() or attributes.attribsToString() instead');
|
'use AttributeMap.prototype.toString() or attributes.attribsToString() instead');
|
||||||
if (!attribs || !['=', '+'].includes(opcode)) return '';
|
if (!attribs || !['=', '+'].includes(opcode)) return '';
|
||||||
|
|
|
@ -100,9 +100,9 @@ const padutils = {
|
||||||
*
|
*
|
||||||
* @param {...*} args - Passed to `console.warn`, with a stack trace appended.
|
* @param {...*} args - Passed to `console.warn`, with a stack trace appended.
|
||||||
*/
|
*/
|
||||||
warnWithStack: (...args) => {
|
warnDeprecated: (...args) => {
|
||||||
const err = new Error();
|
const err = new Error();
|
||||||
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnWithStack);
|
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnDeprecated);
|
||||||
err.name = '';
|
err.name = '';
|
||||||
if (err.stack) args.push(err.stack);
|
if (err.stack) args.push(err.stack);
|
||||||
console.warn(...args);
|
console.warn(...args);
|
||||||
|
|
Loading…
Reference in a new issue