Skip to content
Merged
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
2 changes: 1 addition & 1 deletion loaders/register-static-from-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (source) {
klassName = path.node.id.name;
},
ClassMethod(path) {
if (path.node.static && path.node.async && path.node.key.name.split(/[A-Z]/)[0] !== 'start') {
if (path.node.static && path.node.async && !path.node.key.name.startsWith('_')) {
methodNames.push(path.node.key.name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion loaders/remove-static-from-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function removeStaticFromClient(source) {
const injection = injections[position];
if (position && injection) {
const location = injection.end - position;
if (injection.name.split(/[A-Z]/)[0] === 'start') {
if (injection.name.startsWith('_')) {
code = code.substring(location).trimStart();
} else {
code = `static ${injection.name} = Nullstack.invoke('${injection.name}', '${hash}');` + code.substring(location);
Expand Down
1 change: 0 additions & 1 deletion tests/src/Application.njs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import PluginAttributes from './PluginAttributes';
import PublicServerFunctions from './PublicServerFunctions.njs';
import PureComponents from './PureComponents';
import WebpackCustomPlugin from './WebpackCustomPlugin';
import RemoveStart from './RemoveStart';
import RenderableComponent from './RenderableComponent';
import RoutesAndParams from './RoutesAndParams';
import ServerFunctions from './ServerFunctions';
Expand Down
32 changes: 0 additions & 32 deletions tests/src/RemoveStart.njs

This file was deleted.

19 changes: 0 additions & 19 deletions tests/src/RemoveStart.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions tests/src/ServerFunctions.njs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ class ServerFunctions extends Nullstack {
return string === decodedString
}

static async _privateFunction() {
return true
}

async initiate() {
this.statement = await this.useNodeFileSystem();
this.response = await this.useFetchInNode();
this.doublePlusOneServer = await ServerFunctions.getDoublePlusOne({ number: 34 })
}

async hydrate() {
this.underlineRemovedFromClient = !ServerFunctions._privateFunction;
this.clientOnly = clientOnly();
this.doublePlusOneClient = await ServerFunctions.getDoublePlusOne({ number: 34 })
this.acceptsSpecialCharacters = await this.getEncodedString({ string: decodedString })
Expand All @@ -85,6 +90,7 @@ class ServerFunctions extends Nullstack {
<div data-double-plus-one-server={this.doublePlusOneServer === 69} />
<div data-double-plus-one-client={this.doublePlusOneClient === 69} />
<div data-accepts-special-characters={this.acceptsSpecialCharacters} />
<div data-underline-removed-from-client={this.underlineRemovedFromClient} />
</div>
)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/src/ServerFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ describe('ServerFunctions', () => {
expect(element).toBeTruthy();
});

test('server functions starting with underline are removed from client', async () => {
await page.waitForSelector('[data-underline-removed-from-client]');
const element = await page.$('[data-underline-removed-from-client]');
expect(element).toBeTruthy();
});

});