Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/pug-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ function pug_attr(key, val, escaped, terse) {
) {
val = val.toJSON();
}
if (typeof val === 'bigint') {
val = val.toString();
}
if (typeof val !== 'string') {
val = JSON.stringify(val);
if (!escaped && val.indexOf('"') !== -1) {
Expand Down
10 changes: 10 additions & 0 deletions packages/pug-runtime/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ addTest('attr', function(attr) {
expect(attr('key', 500, true, false)).toBe(' key="500"');
expect(attr('key', 500, false, false)).toBe(' key="500"');

// BigInt attributes
expect(attr('key', BigInt(500), true, true)).toBe(' key="500"');
expect(attr('key', BigInt(500), false, true)).toBe(' key="500"');
expect(attr('key', BigInt(500), true, false)).toBe(' key="500"');
expect(attr('key', BigInt(500), false, false)).toBe(' key="500"');
// BigInt preserves precision beyond Number.MAX_SAFE_INTEGER
expect(attr('key', BigInt('9007199254740993'), true, true)).toBe(
' key="9007199254740993"'
);

// String attributes
expect(attr('key', 'foo', true, true)).toBe(' key="foo"');
expect(attr('key', 'foo', false, true)).toBe(' key="foo"');
Expand Down