Skip to content

Commit ccd5de2

Browse files
committed
Exported static errors as constant
1 parent 4e739b9 commit ccd5de2

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/errors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const INVALID_CONTENT = 'Invalid content';
2+
export const INVALID_SRC_ATTR = 'Invalid worker attribute';
3+
export const INVALID_WORKER_ATTR = 'Invalid worker attribute';

esm/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { listener, addAllListeners } from './listeners.js';
99

1010
export { define, whenDefined } from './custom.js';
1111
export { env } from './listeners.js';
12+
export * from './errors.js';
1213
export const XWorker = xworker();
1314

1415
const INTERPRETER_SELECTORS = selectors.join(',');

esm/worker/url.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { INVALID_CONTENT, INVALID_SRC_ATTR, INVALID_WORKER_ATTR } from '../errors.js';
2+
13
import { dedent } from '../utils.js';
24

35
const hasCommentsOnly = text => !text
@@ -13,11 +15,11 @@ export default element => {
1315
let { value } = worker;
1416
// throw on worker values as ambiguous
1517
// @see https://github.com/pyscript/polyscript/issues/43
16-
if (value) throw new SyntaxError('Invalid worker attribute');
18+
if (value) throw new SyntaxError(INVALID_WORKER_ATTR);
1719
value = src?.value;
1820
if (!value) {
1921
// throw on empty src attributes
20-
if (src) throw new SyntaxError('Invalid src attribute');
22+
if (src) throw new SyntaxError(INVALID_SRC_ATTR);
2123
if (!element.childElementCount)
2224
value = element.textContent;
2325
else {
@@ -40,6 +42,6 @@ export default element => {
4042
}
4143
// validate ambiguous cases with src and not empty/commented content
4244
if (src && !hasCommentsOnly(element.textContent))
43-
throw new SyntaxError('Invalid content');
45+
throw new SyntaxError(INVALID_CONTENT);
4446
};
4547
/* c8 ignore stop */

0 commit comments

Comments
 (0)