-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract validation logic (#1108)
- Loading branch information
1 parent
b461900
commit 1f160df
Showing
10 changed files
with
148 additions
and
162 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,61 @@ | ||
import { | ||
isPlainObject, | ||
isFunctionalComponent, | ||
isConstructor | ||
} from './validators' | ||
import { VUE_VERSION } from './consts' | ||
import { compileTemplateForSlots } from './compile-template' | ||
import { throwError } from './util' | ||
import { validateSlots } from './validate-slots' | ||
|
||
function vueExtendUnsupportedOption (option) { | ||
return `options.${option} is not supported for ` + | ||
`components created with Vue.extend in Vue < 2.3. ` + | ||
`You can set ${option} to false to mount the component.` | ||
} | ||
// these options aren't supported if Vue is version < 2.3 | ||
// for components using Vue.extend. This is due to a bug | ||
// that means the mixins we use to add properties are not applied | ||
// correctly | ||
const UNSUPPORTED_VERSION_OPTIONS = [ | ||
'mocks', | ||
'stubs', | ||
'localVue' | ||
] | ||
|
||
export function validateOptions (options, component) { | ||
if (options.parentComponent && !isPlainObject(options.parentComponent)) { | ||
throwError( | ||
`options.parentComponent should be a valid Vue component options object` | ||
) | ||
} | ||
|
||
if (!isFunctionalComponent(component) && options.context) { | ||
throwError( | ||
`mount.context can only be used when mounting a functional component` | ||
) | ||
} | ||
|
||
if (options.context && !isPlainObject(options.context)) { | ||
throwError('mount.context must be an object') | ||
} | ||
|
||
if ( | ||
VUE_VERSION < 2.3 && isConstructor(component) | ||
) { | ||
UNSUPPORTED_VERSION_OPTIONS.forEach((option) => { | ||
if (options[option]) { | ||
throwError(vueExtendUnsupportedOption(option)) | ||
} | ||
}) | ||
} | ||
|
||
if (options.slots) { | ||
compileTemplateForSlots(options.slots) | ||
// validate slots outside of the createSlots function so | ||
// that we can throw an error without it being caught by | ||
// the Vue error handler | ||
// $FlowIgnore | ||
validateSlots(options.slots) | ||
} | ||
} |
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
Oops, something went wrong.