Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rollup/rollup into sync-d…
Browse files Browse the repository at this point in the history
…d1a6bee
  • Loading branch information
docschina-bot committed Jul 3, 2024
2 parents 3ea56f5 + dd1a6be commit dba0d85
Show file tree
Hide file tree
Showing 59 changed files with 389 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ast/nodes/ClassBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import ClassBodyScope from '../scopes/ClassBodyScope';
import type MethodDefinition from './MethodDefinition';
import type * as NodeType from './NodeType';
import type PropertyDefinition from './PropertyDefinition';
import type StaticBlock from './StaticBlock';
import type ClassNode from './shared/ClassNode';
import { type GenericEsTreeNode, type IncludeChildren, NodeBase } from './shared/Node';

export default class ClassBody extends NodeBase {
declare body: (MethodDefinition | PropertyDefinition)[];
declare body: (MethodDefinition | PropertyDefinition | StaticBlock)[];
declare scope: ClassBodyScope;
declare type: NodeType.tClassBody;

Expand Down
6 changes: 5 additions & 1 deletion src/ast/nodes/StaticBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import BlockScope from '../scopes/BlockScope';
import type ChildScope from '../scopes/ChildScope';
import type * as NodeType from './NodeType';
import * as NodeType from './NodeType';
import { type IncludeChildren, StatementBase, type StatementNode } from './shared/Node';

export default class StaticBlock extends StatementBase {
Expand Down Expand Up @@ -43,3 +43,7 @@ export default class StaticBlock extends StatementBase {
}
}
}

export function isStaticBlock(statement: StatementNode): statement is StaticBlock {
return statement.type === NodeType.StaticBlock;
}
3 changes: 3 additions & 0 deletions src/ast/nodes/shared/ClassNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type ClassBody from '../ClassBody';
import Identifier from '../Identifier';
import type Literal from '../Literal';
import MethodDefinition from '../MethodDefinition';
import { isStaticBlock } from '../StaticBlock';
import { type ExpressionEntity, type LiteralValueOrUnknown } from './Expression';
import { type ExpressionNode, type IncludeChildren, NodeBase } from './Node';
import { ObjectEntity, type ObjectProperty } from './ObjectEntity';
Expand Down Expand Up @@ -122,6 +123,7 @@ export default class ClassNode extends NodeBase implements DeoptimizableEntity {
this.deoptimized = true;
for (const definition of this.body.body) {
if (
!isStaticBlock(definition) &&
!(
definition.static ||
(definition instanceof MethodDefinition && definition.kind === 'constructor')
Expand All @@ -141,6 +143,7 @@ export default class ClassNode extends NodeBase implements DeoptimizableEntity {
const staticProperties: ObjectProperty[] = [];
const dynamicMethods: ObjectProperty[] = [];
for (const definition of this.body.body) {
if (isStaticBlock(definition)) continue;
const properties = definition.static ? staticProperties : dynamicMethods;
const definitionKind = (definition as MethodDefinition | { kind: undefined }).kind;
// Note that class fields do not end up on the prototype
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sanitizeFileName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://datatracker.ietf.org/doc/html/rfc2396
// eslint-disable-next-line no-control-regex
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$&*+,:;<=>?[\]^`{|}\u007F]/g;
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$%&*+,:;<=>?[\]^`{|}\u007F]/g;
const DRIVE_LETTER_REGEX = /^[a-z]:/i;

export function sanitizeFileName(name: string): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = defineTest({
description: 'make sure illegal percent encoding is sanitized',
options: {
input: ['main.js']
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define((function () { 'use strict';

function module1() {
console.log('foo%20bar');
}

function module2() {
console.log('foo%bar');
}

function module3() {
console.log('foo%E3%81%82bar');
}

function module4() {
console.log('foo%E3%81bar');
}

module1();
module2();
module3();
module4();

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

function module1() {
console.log('foo%20bar');
}

function module2() {
console.log('foo%bar');
}

function module3() {
console.log('foo%E3%81%82bar');
}

function module4() {
console.log('foo%E3%81bar');
}

module1();
module2();
module3();
module4();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function module1() {
console.log('foo%20bar');
}

function module2() {
console.log('foo%bar');
}

function module3() {
console.log('foo%E3%81%82bar');
}

function module4() {
console.log('foo%E3%81bar');
}

module1();
module2();
module3();
module4();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
System.register([], (function () {
'use strict';
return {
execute: (function () {

function module1() {
console.log('foo%20bar');
}

function module2() {
console.log('foo%bar');
}

function module3() {
console.log('foo%E3%81%82bar');
}

function module4() {
console.log('foo%E3%81bar');
}

module1();
module2();
module3();
module4();

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function module1() {
console.log('foo%20bar');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function module3() {
console.log('foo%E3%81%82bar');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function module4() {
console.log('foo%E3%81bar');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function module2() {
console.log('foo%bar');
}
9 changes: 9 additions & 0 deletions test/chunking-form/samples/sanitize-percent-encoding1/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { module1 } from './foo%20bar';
import { module2 } from './foo%bar';
import { module3 } from './foo%E3%81%82bar';
import { module4 } from './foo%E3%81bar';

module1();
module2();
module3();
module4();
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = defineTest({
description: 'make sure illegal percent encoding is sanitized for dynamic imports',
options: {
input: ['main.js']
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define((function () { 'use strict';

console.log('foo%20bar');

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define((function () { 'use strict';

console.log('foo%E3%81%82bar');

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define((function () { 'use strict';

console.log('foo%E3%81bar');

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define((function () { 'use strict';

console.log('foo%bar');

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
define(['require', 'exports'], (function (require, exports) { 'use strict';

const lazy1 = new Promise(function (resolve, reject) { require(['./generated-foo_20bar'], resolve, reject); });
const lazy2 = new Promise(function (resolve, reject) { require(['./generated-foo_bar'], resolve, reject); });
const lazy3 = new Promise(function (resolve, reject) { require(['./generated-foo_E3_81_82bar'], resolve, reject); });
const lazy4 = new Promise(function (resolve, reject) { require(['./generated-foo_E3_81bar'], resolve, reject); });

exports.lazy1 = lazy1;
exports.lazy2 = lazy2;
exports.lazy3 = lazy3;
exports.lazy4 = lazy4;

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('foo%20bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('foo%E3%81%82bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('foo%E3%81bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('foo%bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const lazy1 = Promise.resolve().then(function () { return require('./generated-foo_20bar.js'); });
const lazy2 = Promise.resolve().then(function () { return require('./generated-foo_bar.js'); });
const lazy3 = Promise.resolve().then(function () { return require('./generated-foo_E3_81_82bar.js'); });
const lazy4 = Promise.resolve().then(function () { return require('./generated-foo_E3_81bar.js'); });

exports.lazy1 = lazy1;
exports.lazy2 = lazy2;
exports.lazy3 = lazy3;
exports.lazy4 = lazy4;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%20bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%E3%81%82bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%E3%81bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const lazy1 = import('./generated-foo_20bar.js');
const lazy2 = import('./generated-foo_bar.js');
const lazy3 = import('./generated-foo_E3_81_82bar.js');
const lazy4 = import('./generated-foo_E3_81bar.js');

export { lazy1, lazy2, lazy3, lazy4 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], (function () {
'use strict';
return {
execute: (function () {

console.log('foo%20bar');

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], (function () {
'use strict';
return {
execute: (function () {

console.log('foo%E3%81%82bar');

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], (function () {
'use strict';
return {
execute: (function () {

console.log('foo%E3%81bar');

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], (function () {
'use strict';
return {
execute: (function () {

console.log('foo%bar');

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
System.register([], (function (exports, module) {
'use strict';
return {
execute: (function () {

const lazy1 = exports("lazy1", module.import('./generated-foo_20bar.js'));
const lazy2 = exports("lazy2", module.import('./generated-foo_bar.js'));
const lazy3 = exports("lazy3", module.import('./generated-foo_E3_81_82bar.js'));
const lazy4 = exports("lazy4", module.import('./generated-foo_E3_81bar.js'));

})
};
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%20bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%E3%81%82bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%E3%81bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo%bar');
4 changes: 4 additions & 0 deletions test/chunking-form/samples/sanitize-percent-encoding2/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const lazy1 = import('./foo%20bar');
export const lazy2 = import('./foo%bar');
export const lazy3 = import('./foo%E3%81%82bar');
export const lazy4 = import('./foo%E3%81bar');
20 changes: 20 additions & 0 deletions test/chunking-form/samples/sanitize-percent-encoding3/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = defineTest({
description: 'make sure illegal percent encoding is sanitized for virtual entry points',
options: {
input: ['main'],
plugins: [
{
options(options) {
options.input = ['foo%bar', 'foo%20bar', 'foo%E3%81%82bar', 'foo%E3%81bar'];
return options;
},
resolveId(id) {
return id;
},
load(id) {
return 'export default ' + JSON.stringify(id);
}
}
]
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define((function () { 'use strict';

var foo_20bar = "foo%20bar";

return foo_20bar;

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define((function () { 'use strict';

var foo_E3_81_82bar = "foo%E3%81%82bar";

return foo_E3_81_82bar;

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define((function () { 'use strict';

var foo_E3_81bar = "foo%E3%81bar";

return foo_E3_81bar;

}));
Loading

0 comments on commit dba0d85

Please sign in to comment.