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
62 changes: 62 additions & 0 deletions packages/plugin-rsc/src/transforms/fixtures/hoist/methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const key = 'computed'
const __proto__ = 'computed-proto'

export function createObject(value) {
return {
async action(arg) {
'use server'
return value + arg
},
async [key]() {
'use server'
return value + 1
},
async __proto__() {
'use server'
return value + 2
},
async [__proto__]() {
'use server'
return value + 3
},
async 'foo-bar'() {
'use server'
return value + 4
},
async 1.5() {
'use server'
return value + 5
},
}
}

export class Actions {
static async action() {
'use server'
return 1
}

static async ['computed']() {
'use server'
return 2
}

static async [key]() {
'use server'
return 3
}

static async constructor() {
'use server'
return 4
}
}

export function createActions(value) {
return class Actions {
static async action() {
'use server'
return value
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const key = 'computed'
const __proto__ = 'computed-proto'

export function createObject(value) {
return {
["action"]: /* #__PURE__ */ $$register($$hoist_0_action, "<id>", "$$hoist_0_action").bind(null, __enc([value])),
[key]: /* #__PURE__ */ $$register($$hoist_1_anonymous_server_function, "<id>", "$$hoist_1_anonymous_server_function").bind(null, __enc([value])),
["__proto__"]: /* #__PURE__ */ $$register($$hoist_2___proto__, "<id>", "$$hoist_2___proto__").bind(null, __enc([value])),
[__proto__]: /* #__PURE__ */ $$register($$hoist_3_anonymous_server_function, "<id>", "$$hoist_3_anonymous_server_function").bind(null, __enc([value])),
['foo-bar']: /* #__PURE__ */ $$register($$hoist_4_anonymous_server_function, "<id>", "$$hoist_4_anonymous_server_function").bind(null, __enc([value])),
[1.5]: /* #__PURE__ */ $$register($$hoist_5_anonymous_server_function, "<id>", "$$hoist_5_anonymous_server_function").bind(null, __enc([value])),
}
}

export class Actions {
static ["action"] = /* #__PURE__ */ $$register($$hoist_6_action, "<id>", "$$hoist_6_action");

static ['computed'] = /* #__PURE__ */ $$register($$hoist_7_anonymous_server_function, "<id>", "$$hoist_7_anonymous_server_function");

static [key] = /* #__PURE__ */ $$register($$hoist_8_anonymous_server_function, "<id>", "$$hoist_8_anonymous_server_function");

static ["constructor"] = /* #__PURE__ */ $$register($$hoist_9_constructor, "<id>", "$$hoist_9_constructor");
}

export function createActions(value) {
return class Actions {
static ["action"] = /* #__PURE__ */ $$register($$hoist_10_action, "<id>", "$$hoist_10_action").bind(null, __enc([value]));
}
}

;export async function $$hoist_0_action($$hoist_encoded, arg) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + arg
};
/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" });

;export async function $$hoist_1_anonymous_server_function($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + 1
};
/* #__PURE__ */ Object.defineProperty($$hoist_1_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_2___proto__($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + 2
};
/* #__PURE__ */ Object.defineProperty($$hoist_2___proto__, "name", { value: "__proto__" });

;export async function $$hoist_3_anonymous_server_function($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + 3
};
/* #__PURE__ */ Object.defineProperty($$hoist_3_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_4_anonymous_server_function($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + 4
};
/* #__PURE__ */ Object.defineProperty($$hoist_4_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_5_anonymous_server_function($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value + 5
};
/* #__PURE__ */ Object.defineProperty($$hoist_5_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_6_action() {
'use server'
return 1
};
/* #__PURE__ */ Object.defineProperty($$hoist_6_action, "name", { value: "action" });

;export async function $$hoist_7_anonymous_server_function() {
'use server'
return 2
};
/* #__PURE__ */ Object.defineProperty($$hoist_7_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_8_anonymous_server_function() {
'use server'
return 3
};
/* #__PURE__ */ Object.defineProperty($$hoist_8_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_9_constructor() {
'use server'
return 4
};
/* #__PURE__ */ Object.defineProperty($$hoist_9_constructor, "name", { value: "constructor" });

;export async function $$hoist_10_action($$hoist_encoded) {
const [value] = __dec($$hoist_encoded);
'use server'
return value
};
/* #__PURE__ */ Object.defineProperty($$hoist_10_action, "name", { value: "action" });
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const key = 'computed'
const __proto__ = 'computed-proto'

export function createObject(value) {
return {
["action"]: /* #__PURE__ */ $$register($$hoist_0_action, "<id>", "$$hoist_0_action").bind(null, value),
[key]: /* #__PURE__ */ $$register($$hoist_1_anonymous_server_function, "<id>", "$$hoist_1_anonymous_server_function").bind(null, value),
["__proto__"]: /* #__PURE__ */ $$register($$hoist_2___proto__, "<id>", "$$hoist_2___proto__").bind(null, value),
[__proto__]: /* #__PURE__ */ $$register($$hoist_3_anonymous_server_function, "<id>", "$$hoist_3_anonymous_server_function").bind(null, value),
['foo-bar']: /* #__PURE__ */ $$register($$hoist_4_anonymous_server_function, "<id>", "$$hoist_4_anonymous_server_function").bind(null, value),
[1.5]: /* #__PURE__ */ $$register($$hoist_5_anonymous_server_function, "<id>", "$$hoist_5_anonymous_server_function").bind(null, value),
}
}

export class Actions {
static ["action"] = /* #__PURE__ */ $$register($$hoist_6_action, "<id>", "$$hoist_6_action");

static ['computed'] = /* #__PURE__ */ $$register($$hoist_7_anonymous_server_function, "<id>", "$$hoist_7_anonymous_server_function");

static [key] = /* #__PURE__ */ $$register($$hoist_8_anonymous_server_function, "<id>", "$$hoist_8_anonymous_server_function");

static ["constructor"] = /* #__PURE__ */ $$register($$hoist_9_constructor, "<id>", "$$hoist_9_constructor");
}

export function createActions(value) {
return class Actions {
static ["action"] = /* #__PURE__ */ $$register($$hoist_10_action, "<id>", "$$hoist_10_action").bind(null, value);
}
}

;export async function $$hoist_0_action(value, arg) {
'use server'
return value + arg
};
/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" });

;export async function $$hoist_1_anonymous_server_function(value) {
'use server'
return value + 1
};
/* #__PURE__ */ Object.defineProperty($$hoist_1_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_2___proto__(value) {
'use server'
return value + 2
};
/* #__PURE__ */ Object.defineProperty($$hoist_2___proto__, "name", { value: "__proto__" });

;export async function $$hoist_3_anonymous_server_function(value) {
'use server'
return value + 3
};
/* #__PURE__ */ Object.defineProperty($$hoist_3_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_4_anonymous_server_function(value) {
'use server'
return value + 4
};
/* #__PURE__ */ Object.defineProperty($$hoist_4_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_5_anonymous_server_function(value) {
'use server'
return value + 5
};
/* #__PURE__ */ Object.defineProperty($$hoist_5_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_6_action() {
'use server'
return 1
};
/* #__PURE__ */ Object.defineProperty($$hoist_6_action, "name", { value: "action" });

;export async function $$hoist_7_anonymous_server_function() {
'use server'
return 2
};
/* #__PURE__ */ Object.defineProperty($$hoist_7_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_8_anonymous_server_function() {
'use server'
return 3
};
/* #__PURE__ */ Object.defineProperty($$hoist_8_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_9_constructor() {
'use server'
return 4
};
/* #__PURE__ */ Object.defineProperty($$hoist_9_constructor, "name", { value: "constructor" });

;export async function $$hoist_10_action(value) {
'use server'
return value
};
/* #__PURE__ */ Object.defineProperty($$hoist_10_action, "name", { value: "action" });
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const key = 'computed'

export function createObject(value) {
return {
async [getKey(key, value)]() {
'use server'
return value
},
}
}

export class Actions {
static async action() {
'use server'
return 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## hoist

```txt
(0:0) "const key = 'computed'\n" --> (0:0) "const key = 'computed'\n"
(2:0) "export function createObject(value) {\n" --> (2:0) "export function createObject(value) {\n"
(3:0) " return {\n" --> (3:0) " return {\n"
(4:0) " async [getKey(key, value)]() {\n" --> (4:0) " [getKey(key, value)]: /* #__PURE__ */ registerServerReference($$hoist_0_anonymous_server_function, \"$$hoist_0_anonymous_server_function\").bind(null, encrypt([value]))"
(7:5) ",\n" --> (4:170) ",\n"
(8:0) " }\n" --> (5:0) " }\n"
(9:0) "}\n" --> (6:0) "}\n"
(11:0) "export class Actions {\n" --> (8:0) "export class Actions {\n"
(12:0) " static async action() {\n" --> (9:0) " static [\"action\"] = /* #__PURE__ */ registerServerReference($$hoist_1_action, \"$$hoist_1_action\");\n"
(16:0) "}\n" --> (10:0) "}\n"
(4:30) "() {\n" --> (11:0) "\n"
(4:30) "() " --> (12:0) ";export async function $$hoist_0_anonymous_server_function($$hoist_encoded) "
(4:33) "{\n" --> (12:76) "{\n"
(5:0) " 'use server'\n" --> (13:0) " const [value] = await decrypt($$hoist_encoded);\n"
(5:6) "'use server'\n" --> (14:0) "'use server'\n"
(6:0) " return value\n" --> (15:0) " return value\n"
(7:0) " },\n" --> (16:0) " };\n"
[unmapped] --> (17:0) "/* #__PURE__ */ Object.defineProperty($$hoist_0_anonymous_server_function, \"name\", { value: \"anonymous_server_function\" });\n"
(12:21) "() {\n" --> (18:0) "\n"
(12:21) "() " --> (19:0) ";export async function $$hoist_1_action() "
(12:24) "{\n" --> (19:42) "{\n"
(13:0) " 'use server'\n" --> (20:0) " 'use server'\n"
(14:0) " return 1\n" --> (21:0) " return 1\n"
(15:0) " }\n" --> (22:0) " };\n"
[unmapped] --> (23:0) "/* #__PURE__ */ Object.defineProperty($$hoist_1_action, \"name\", { value: \"action\" });\n"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Input

```js
const key = 'computed'

export function createObject(value) {
return {
async [getKey(key, value)]() {
'use server'
return value
},
}
}

export class Actions {
static async action() {
'use server'
return 1
}
}
```

## hoist

**Status:** transformed

**References:** $$hoist_0_anonymous_server_function, $$hoist_1_action

[Source map visualization](https://evanw.github.io/source-map-visualization/#ODQwAGNvbnN0IGtleSA9ICdjb21wdXRlZCcKCmV4cG9ydCBmdW5jdGlvbiBjcmVhdGVPYmplY3QodmFsdWUpIHsKICByZXR1cm4gewogICAgW2dldEtleShrZXksIHZhbHVlKV06IC8qICNfX1BVUkVfXyAqLyByZWdpc3RlclNlcnZlclJlZmVyZW5jZSgkJGhvaXN0XzBfYW5vbnltb3VzX3NlcnZlcl9mdW5jdGlvbiwgIiQkaG9pc3RfMF9hbm9ueW1vdXNfc2VydmVyX2Z1bmN0aW9uIikuYmluZChudWxsLCBlbmNyeXB0KFt2YWx1ZV0pKSwKICB9Cn0KCmV4cG9ydCBjbGFzcyBBY3Rpb25zIHsKICBzdGF0aWMgWyJhY3Rpb24iXSA9IC8qICNfX1BVUkVfXyAqLyByZWdpc3RlclNlcnZlclJlZmVyZW5jZSgkJGhvaXN0XzFfYWN0aW9uLCAiJCRob2lzdF8xX2FjdGlvbiIpOwp9Cgo7ZXhwb3J0IGFzeW5jIGZ1bmN0aW9uICQkaG9pc3RfMF9hbm9ueW1vdXNfc2VydmVyX2Z1bmN0aW9uKCQkaG9pc3RfZW5jb2RlZCkgewogICAgICBjb25zdCBbdmFsdWVdID0gYXdhaXQgZGVjcnlwdCgkJGhvaXN0X2VuY29kZWQpOwondXNlIHNlcnZlcicKICAgICAgcmV0dXJuIHZhbHVlCiAgICB9OwovKiAjX19QVVJFX18gKi8gT2JqZWN0LmRlZmluZVByb3BlcnR5KCQkaG9pc3RfMF9hbm9ueW1vdXNfc2VydmVyX2Z1bmN0aW9uLCAibmFtZSIsIHsgdmFsdWU6ICJhbm9ueW1vdXNfc2VydmV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0FBQyxHQUFHLENBQUMsTUFBTTtBQUNqQixDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUM7QUFDYixDQUFDLENBQUMsQ0FBQyxDQUFDOztBQUtpQjtBQUFBLDBDQUFHO0FBQ3hCLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsTUFBTTtBQUNmLENBQUMsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDO0FBQ1gsQ0FBQyxDQUFDOzsifQ==)

```js
const key = 'computed'

export function createObject(value) {
return {
[getKey(key, value)]: /* #__PURE__ */ registerServerReference($$hoist_0_anonymous_server_function, "$$hoist_0_anonymous_server_function").bind(null, encrypt([value])),
}
}

export class Actions {
static ["action"] = /* #__PURE__ */ registerServerReference($$hoist_1_action, "$$hoist_1_action");
}

;export async function $$hoist_0_anonymous_server_function($$hoist_encoded) {
const [value] = await decrypt($$hoist_encoded);
'use server'
return value
};
/* #__PURE__ */ Object.defineProperty($$hoist_0_anonymous_server_function, "name", { value: "anonymous_server_function" });

;export async function $$hoist_1_action() {
'use server'
return 1
};
/* #__PURE__ */ Object.defineProperty($$hoist_1_action, "name", { value: "action" });
```
Loading
Loading