forked from BuilderIO/mitosis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dedupe @babel/types * augment babel types * update yarn * comment * update yarn lock * add missing path for jsx-runtime * remove redundant type workaround * improve replace-identifiers * tweak * refactor, pass hook key * improve logging * debug * remove patch * fix fiddle * revert tsconfig changes * revert to yarn 3.2 * run yarn * add some missing deps for fiddle * undo @babel/types dedupe * remove * always add React.Fragment * bring back _this context workaround in vue * undo react change * use keys for Vue contexts * improve context check * fix for composition api too
- Loading branch information
Showing
9 changed files
with
153 additions
and
110 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
33 changes: 33 additions & 0 deletions
33
packages/core/src/generators/context/helpers/context-with-symbol-key.ts
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { format } from 'prettier/standalone'; | ||
import { stringifyContextValue } from '../../../helpers/get-state-object-string'; | ||
import { MitosisContext } from '../../../types/mitosis-context'; | ||
import { BaseTranspilerOptions } from '../../../types/transpiler'; | ||
|
||
export const getContextWithSymbolKey = | ||
(options: Pick<BaseTranspilerOptions, 'prettier'>) => | ||
({ context }: { context: MitosisContext }): string => { | ||
let str = ` | ||
const key = Symbol(); | ||
export default { | ||
${context.name}: ${stringifyContextValue(context.value)}, | ||
key | ||
} | ||
`; | ||
|
||
if (options.prettier !== false) { | ||
try { | ||
str = format(str, { | ||
parser: 'typescript', | ||
plugins: [ | ||
require('prettier/parser-typescript'), // To support running in browsers | ||
], | ||
}); | ||
} catch (err) { | ||
console.error('Format error for file:', str); | ||
throw err; | ||
} | ||
} | ||
|
||
return str; | ||
}; |
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,38 +1,9 @@ | ||
import { format } from 'prettier/standalone'; | ||
import { stringifyContextValue } from '../../helpers/get-state-object-string'; | ||
import { MitosisContext } from '../../types/mitosis-context'; | ||
import { BaseTranspilerOptions } from '../../types/transpiler'; | ||
import { getContextWithSymbolKey } from './helpers/context-with-symbol-key'; | ||
|
||
interface ContextToSvelteOptions extends Pick<BaseTranspilerOptions, 'prettier'> {} | ||
|
||
/** | ||
* TO-DO: support types | ||
*/ | ||
export const contextToSvelte = | ||
(options: ContextToSvelteOptions = {}) => | ||
({ context }: { context: MitosisContext }): string => { | ||
let str = ` | ||
const key = Symbol(); | ||
export default { | ||
${context.name}: ${stringifyContextValue(context.value)}, | ||
key | ||
} | ||
`; | ||
|
||
if (options.prettier !== false) { | ||
try { | ||
str = format(str, { | ||
parser: 'typescript', | ||
plugins: [ | ||
require('prettier/parser-typescript'), // To support running in browsers | ||
], | ||
}); | ||
} catch (err) { | ||
console.error('Format error for file:', str); | ||
throw err; | ||
} | ||
} | ||
|
||
return str; | ||
}; | ||
export const contextToSvelte = getContextWithSymbolKey; |
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,14 +1,3 @@ | ||
import { MitosisContext } from '../../types/mitosis-context'; | ||
import { getContextWithSymbolKey } from './helpers/context-with-symbol-key'; | ||
|
||
type ContextToVueOptions = { | ||
format?: boolean; | ||
}; | ||
|
||
export function contextToVue(context: MitosisContext, options: ContextToVueOptions = {}): string { | ||
let str = ` | ||
// Noop file | ||
export default {}; | ||
`; | ||
|
||
return str; | ||
} | ||
export const contextToVue = getContextWithSymbolKey; |
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
Oops, something went wrong.