-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
36 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,22 @@ | ||
import { Feature } from './compat'; | ||
|
||
// Used for mapping isomorphic references | ||
export const REFERENCES_KEY = '__SEROVAL_REFS__'; | ||
|
||
export const GLOBAL_CONTEXT_KEY = '__SEROVAL__'; | ||
|
||
export const GLOBAL_CONTEXT_REFERENCES = 'r'; | ||
export const GLOBAL_CONTEXT_REFERENCES = '$R'; | ||
|
||
export const GLOBAL_CONTEXT_RESOLVERS = 's'; | ||
export const GLOBAL_CONTEXT_RESOLVE = 's'; | ||
|
||
export const GLOBAL_CONTEXT_REJECTERS = 'f'; | ||
export const GLOBAL_CONTEXT_REJECT = 'f'; | ||
|
||
export const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR = 'p'; | ||
export const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR = '$P'; | ||
|
||
export const ROOT_REFERENCE = 't'; | ||
|
||
export const GLOBAL_CONTEXT_PARAM = 'o'; | ||
|
||
const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_FUNCTION_BODY = `(s,f,p){return p=new Promise(function(a,b){s=a,f=b}),p.${GLOBAL_CONTEXT_RESOLVERS}=s,p.${GLOBAL_CONTEXT_REJECTERS}=f,p}`; | ||
const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_ARROW_BODY = `(s,f,p)=>(p=new Promise((a,b)=>{s=a,f=b}),p.${GLOBAL_CONTEXT_RESOLVERS}=s,p.${GLOBAL_CONTEXT_REJECTERS}=f,p)`; | ||
const GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_FUNCTION_BODY = `(s,f,p){return p=new Promise(function(a,b){s=a,f=b}),p.${GLOBAL_CONTEXT_RESOLVE}=s,p.${GLOBAL_CONTEXT_REJECT}=f,p}`; | ||
|
||
function getPromiseConstructor(features: number): string { | ||
if (features & Feature.ArrowFunction) { | ||
return `${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_ARROW_BODY}`; | ||
} | ||
if (features & Feature.MethodShorthand) { | ||
return `${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_FUNCTION_BODY}`; | ||
} | ||
return `${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_FUNCTION_BODY}`; | ||
function getPromiseConstructor(): string { | ||
return `function ${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR_FUNCTION_BODY}`; | ||
} | ||
|
||
export function getCrossReferenceHeader(features: number): string { | ||
return `${GLOBAL_CONTEXT_KEY}={${GLOBAL_CONTEXT_REFERENCES}:[],${getPromiseConstructor(features)}};`; | ||
export function getCrossReferenceHeader(): string { | ||
return `${GLOBAL_CONTEXT_REFERENCES}=[];${getPromiseConstructor()};`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters