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
6 changes: 6 additions & 0 deletions snapshots/input/prototype-members/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "prototype-members",
"version": "1.0.0",
"private": true,
"type": "module"
}
113 changes: 113 additions & 0 deletions snapshots/input/prototype-members/src/connection.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
export function Connection() {}

Connection.prototype = {
getSchemaVersion() {
return 0
},
getVersion: function () {
return 1
},
version: 1,
'schema-version': 2,
['computed-version']: 3,
}

// Different spellings of the same property must share one symbol.
Connection.prototype['schema-version'] = 4
Object.defineProperty(Connection.prototype, 'schema-version', {
value: 5,
writable: true,
})
Connection.prototype['computed-version'] = 6

export function DirectConnection() {}

DirectConnection.prototype.getVersion = function () {
return 2
}
DirectConnection.prototype.version = 2

function getSchemaVersion() {
return 3
}
DirectConnection.prototype['getSchemaVersion'] = getSchemaVersion
DirectConnection.prototype['schema-version'] = 3

// Reads and compound writes are references, not member declarations.
DirectConnection.prototype['version'] += 1
DirectConnection.prototype['getSchemaVersion']()

export function BracketConnection() {}

BracketConnection['prototype'] = {
getSchemaVersion() {
return 4
},
getVersion: function () {
return 4
},
version: 4,
}

export function MixedConnection() {}

MixedConnection['prototype'].getVersion = getSchemaVersion
MixedConnection['prototype']['version'] = 5

export function DefinedConnection() {}

Object.defineProperty(DefinedConnection.prototype, 'getVersion', {
value: getSchemaVersion,
})
Object.defineProperty(DefinedConnection['prototype'], 'version', {
value: 14,
writable: true,
})
Object.defineProperty(DefinedConnection.prototype, 'schema-version', {
get() {
return 15
},
})

let currentVersion = 16
Object.defineProperty(DefinedConnection.prototype, 'currentVersion', {
get() {
return currentVersion
},
set(value) {
currentVersion = value
},
})

// A shadowed Object must not introduce a prototype member definition.
/** @param {{ defineProperty: Function }} Object */
export function shadowObject(Object) {
function ShadowedConnection() {}
Object.defineProperty(ShadowedConnection.prototype, 'notAMember', {
value: 17,
})
}

// Ordinary writes must remain references, not new prototype definitions.
export function updateOrdinary(ordinary = { version: 6 }) {
ordinary.version = 7
ordinary['version'] = 8
Object.defineProperty(ordinary, 'version', { value: 9 })
}

// Members of local constructors must keep valid local symbols.
export function localVersion() {
function LocalConnection() {}
LocalConnection.prototype['version'] = 11

function LocalReplacement() {}
LocalReplacement['prototype'] = { version: 12 }

function LocalDefined() {}
Object.defineProperty(LocalDefined.prototype, 'version', { value: 18 })
return [
new LocalConnection().version,
new LocalReplacement().version,
new LocalDefined().version,
]
}
59 changes: 59 additions & 0 deletions snapshots/input/prototype-members/src/use.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/** @import { Connection, DirectConnection, BracketConnection, MixedConnection, DefinedConnection } from './connection.mjs' */

/** @param {Connection} connection */
export function schemaVersion(connection) {
return [
connection.getSchemaVersion(),
connection.getVersion(),
connection.version,
connection['schema-version'],
connection['computed-version'],
]
}

/** @param {DirectConnection} connection */
export function directVersion(connection) {
return [
connection.getVersion(),
connection['getVersion'](),
connection.version,
connection['version'],
connection.getSchemaVersion(),
connection['getSchemaVersion'](),
connection['schema-version'],
]
}

/** @param {BracketConnection} connection */
export function bracketVersion(connection) {
return [
connection.getSchemaVersion(),
connection.getVersion(),
connection.version,
]
}

/** @param {MixedConnection} connection */
export function mixedVersion(connection) {
return [connection.getVersion(), connection.version]
}

/** @param {DefinedConnection} connection */
export function definedVersion(connection) {
connection.currentVersion = 19
return [
connection.getVersion(),
connection['getVersion'](),
connection.version,
connection['schema-version'],
connection.currentVersion,
]
}

/** @param {DirectConnection} connection */
export function updateVersion(connection) {
connection.version = 9
connection['version'] = 10
connection.version += 1
return connection.version
}
11 changes: 11 additions & 0 deletions snapshots/input/prototype-members/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"target": "ES2022"
},
"include": ["src/**/*.mjs"]
}
Loading
Loading