Skip to content

Commit 12b90f8

Browse files
committed
warning deprecation
1 parent dd7bdd3 commit 12b90f8

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/printer.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@ import {
55
} from './common/util.js';
66
import ignoreComments from './comments/ignore.js';
77

8-
let checked = false;
8+
function once(factory) {
9+
let value;
10+
return () => {
11+
if (typeof value === 'undefined') {
12+
value = factory();
13+
}
14+
return value;
15+
};
16+
}
17+
18+
const warnDeprecation = once(() => {
19+
console.warn(`'solidity-parse' has been deprecated, please use 'slang'.`);
20+
return true;
21+
});
922

10-
function prettierVersionCheck() {
11-
if (checked) return;
23+
const prettierVersionCheck = once(() => {
1224
if (!prettierVersionSatisfies('>=2.3.0')) {
1325
throw new Error(
1426
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
1527
);
1628
}
17-
checked = true;
18-
}
29+
return true;
30+
});
1931

2032
function genericPrint(path, options, print) {
33+
warnDeprecation();
2134
prettierVersionCheck();
2235

2336
const node = path.getValue();

src/slangPrinter.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ import type { AstPath, Doc, ParserOptions } from 'prettier';
66
import type { AstNode, StrictAstNode } from './slang-nodes';
77
import type { PrintFunction } from './types';
88

9-
let checked = false;
9+
function once<T>(factory: () => T): () => T {
10+
let value: T;
11+
return (): T => {
12+
if (typeof value === 'undefined') {
13+
value = factory();
14+
}
15+
return value;
16+
};
17+
}
1018

11-
function prettierVersionCheck(): void {
12-
if (checked) return;
19+
const prettierVersionCheck = once((): boolean => {
1320
if (!prettierVersionSatisfies('>=2.3.0')) {
1421
throw new Error(
1522
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
1623
);
1724
}
18-
checked = true;
19-
}
25+
return true;
26+
});
2027

2128
function hasNodeIgnoreComment(node: StrictAstNode): boolean {
2229
// Prettier sets SourceUnit's comments to undefined after assigning comments

0 commit comments

Comments
 (0)